git addã®åãæ¶ãã¨ãã³ãããæ¸ã¿ã®ãã¡ã¤ã«ãé¤å¤ããæ¹æ³
git addãåãæ¶ã
$ git reset HEAD foo.txt
git add ã§ç·¨éå
容ã index ã«è¿½å *1ããã¾ãã
ééã㦠index ã«è¿½å ããå ´åã«ããã®ã³ãã³ãã§åãæ¶ããã§ãã¾ãã
$ git add foo.txt $ git status # On branch master # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # modified: foo.txt # $ git reset HEAD foo.txt Unstaged changes after reset: M foo.txt $ git status # On branch master # Changed but not updated: # (use "git add <file>..." to update what will be committed) # (use "git checkout -- <file>..." to discard changes in working directory) # # modified: foo.txt # no changes added to commit (use "git add" and/or "git commit -a")
ééã㦠foo.txt ã index ã«è¿½å ããåãæ¶ãã¾ããã
$ mkdir test $ cd test/ $ git init Initialized empty Git repository in /Users/myuser/Dev/test/.git/ $ touch foo.txt $ git add foo.txt $ git reset HEAD foo.txt fatal: ambiguous argument 'HEAD': unknown revision or path not in the working tree. Use '--' to separate paths from revisions
ãã ãã¾ã£ããã®ãªãã¸ããªã«åãã¦ã³ãããããéãã³ããããããã¡ã¤ã«ã index ã«è¿½å ãã¾ãããããã¯åãæ¶ããåºæ¥ã¾ããã§ããã
ã³ãããæ¸ã¿ã®ãã¡ã¤ã«ãããªãã¸ããªããæ¶ãã¦.gitignoreã§é¤å¤ãã
$ git rm --cached foo.txt $ echo 'foo.txt' > .gitignore $ git add .gitignore $ git commit -m 'delete and add .gitignore'
æ¢ã«ã³ãããããã¦ããã¡ã¤ã«ããå¾ãã .gitignore ã§é¤å¤ããããªã£ãéãã¾ãã¯ãªãã¸ããªããåé¤ããªãã¨é¤å¤ã§ãã¾ããã
ãªãã¸ããªããã¯æ¶ããããã©ãã¯ã¼ãã³ã°ããªã¼ã«ãããã¡ã¤ã«ã¯ç¾ç¶ã®ã¾ã¾æ®ãã¦ããããå ´åã«ããã®æä½ã§é¤å¤ã§ãã¾ãã
$ git status # On branch master # Changed but not updated: # (use "git add <file>..." to update what will be committed) # (use "git checkout -- <file>..." to discard changes in working directory) # # modified: foo.txt # no changes added to commit (use "git add" and/or "git commit -a") $ git rm --cached foo.txt rm 'foo.txt' $ echo 'foo.txt' > .gitignore $ git add .gitignore $ git status # On branch master # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # new file: .gitignore # deleted: foo.txt # $ git commit -m 'delete and add .gitignore' [master 6bd9dbd] delete and add .gitignore 2 files changed, 1 insertions(+), 1 deletions(-) create mode 100644 .gitignore delete mode 100644 foo.txt $ cat foo.txt foo $ echo 'bar' > foo.txt $ git status # On branch master nothing to commit (working directory clean) $ cat foo.txt bar
foo.txt ããªãã¸ããªããæ¶ãã¤ã¤ .gitignore 㧠foo.txt ãé¤å¤ãã¾ããã
*1:indexã¯stageã¨ãå¼ã°ããã½ããgit status ã§è¡¨ç¤ºããã説æã§ã¯ git addãåãæ¶ãäºã« unstage ã¨ããåè©ã使ã£ã¦ã¾ãã