Statuses of resources
TweetPosted on Sunday Mar 09, 2014 at 08:28AM in Technology
Statuses
- untracked
- unmodified
- modified
- staged
untracked
- Newly created file what not connected to the any part of git.
- We use git add to connect these file to git.
unmodified
- Files connected to git but no changes were made yet.
modified
- Files connected to git and modified.
- When we do commit with this kind of resources only, no changes will be made.
staged
- Files connected to git and modified, and declared to commit next time.
Examples of an newly created file
Create a repository
kyle-no-MacBook:gitprac5 kyle$ git init Initialized empty Git repository in /Users/kyle/tmp/gitprac5/.git/ kyle-no-MacBook:gitprac5 kyle$
Create a file
kyle-no-MacBook:gitprac5 kyle$ echo hoge > hoge.txt kyle-no-MacBook:gitprac5 kyle$ git status # On branch master # # Initial commit # # Untracked files: # (use "git add <file>..." to include in what will be committed) # # hoge.txt nothing added to commit but untracked files present (use "git add" to track) kyle-no-MacBook:gitprac5 kyle$
- Now hoge.txt is untracked.
Add to Index
kyle-no-MacBook:gitprac5 kyle$ git add hoge.txt kyle-no-MacBook:gitprac5 kyle$ git status # On branch master # # Initial commit # # Changes to be committed: # (use "git rm --cached <file>..." to unstage) # # new file: hoge.txt # kyle-no-MacBook:gitprac5 kyle$
- Now README is staged (?).
Commit
kyle-no-MacBook:gitprac5 kyle$ git commit -m 'initial' [master (root-commit) ffbe516] initial 1 file changed, 1 insertion(+) create mode 100644 hoge.txt kyle-no-MacBook:gitprac5 kyle$ git status # On branch master nothing to commit, working directory clean kyle-no-MacBook:gitprac5 kyle$
- Now README is unmodified.
Cancel git add to new file
- We can cancel it like this:
kyle-no-MacBook:gitprac5 kyle$ echo README! > README kyle-no-MacBook:gitprac5 kyle$ git status # On branch master # Untracked files: # (use "git add <file>..." to include in what will be committed) # # README nothing added to commit but untracked files present (use "git add" to track) kyle-no-MacBook:gitprac5 kyle$ git add README kyle-no-MacBook:gitprac5 kyle$ git status # On branch master # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # new file: README # kyle-no-MacBook:gitprac5 kyle$ git reset HEAD README kyle-no-MacBook:gitprac5 kyle$ git status # On branch master # Untracked files: # (use "git add <file>..." to include in what will be committed) # # README nothing added to commit but untracked files present (use "git add" to track) kyle-no-MacBook:gitprac5 kyle$
- Also this deletes all of untracked files:
kyle-no-MacBook:gitprac5 kyle$ git clean -f Removing README kyle-no-MacBook:gitprac5 kyle$ ls -l total 8 -rw-r--r--+ 1 kyle staff 5 3 9 08:40 hoge.txt kyle-no-MacBook:gitprac5 kyle$ git status # On branch master nothing to commit, working directory clean kyle-no-MacBook:gitprac5 kyle$
Examples of existing file that already tracked by git
kyle-no-MacBook:gitprac5 kyle$ echo hogehoge >> hoge.txt kyle-no-MacBook:gitprac5 kyle$ git status # On branch master # Changes not staged for commit: # (use "git add <file>..." to update what will be committed) # (use "git checkout -- <file>..." to discard changes in working directory) # # modified: hoge.txt # no changes added to commit (use "git add" and/or "git commit -a") kyle-no-MacBook:gitprac5 kyle$
- Now hoge.txt modified but not staged.
kyle-no-MacBook:gitprac5 kyle$ git add hoge.txt kyle-no-MacBook:gitprac5 kyle$ git status # On branch master # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # modified: hoge.txt # kyle-no-MacBook:gitprac5 kyle$
- Now hoge.txt staged.
- Let's take one more modify.
kyle-no-MacBook:gitprac5 kyle$ echo hogehogehoge >> hoge.txt kyle-no-MacBook:gitprac5 kyle$ git status # On branch master # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # modified: hoge.txt # # Changes not staged for commit: # (use "git add <file>..." to update what will be committed) # (use "git checkout -- <file>..." to discard changes in working directory) # # modified: hoge.txt # kyle-no-MacBook:gitprac5 kyle$
- This means last change (hogehogehoge) will not send by next commit.
- Next commit will send the change (hogehoge) only.
- So when you want to commit (hogehogehoge) next time, you need to execute git add once again.
kyle-no-MacBook:gitprac5 kyle$ git add hoge.txt kyle-no-MacBook:gitprac5 kyle$ git status # On branch master # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # modified: hoge.txt # kyle-no-MacBook:gitprac5 kyle$
References
Tags: git