My Git Experiment While Working on Commits
While I was working with my code, I noticed that something about git wasn’t the way I understood it should. Here are my experiments.
git commit w/o filename
songserm@songserm-ubt:~/Dropbox/projects/git-dummy/boulder$ git add broadway
songserm@songserm-ubt:~/Dropbox/projects/git-dummy/boulder$ git status
# On branch master
# Your branch is ahead of 'origin/master' by 2 commits.
#
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# new file: broadway
#
# 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: folsom
#
“Changes to be commited:” means that if you do a git commit
w/o filenames, it will commit these files.
Why? it’s because those files are in index tree (i.e. stagging tree) and ready to be committed.
songserm@songserm-ubt:~/Dropbox/projects/git-dummy/boulder$ git commit -m "add broadway"
[master 4c9bd0d] add broadway
0 files changed
create mode 100644 boulder/broadway
songserm@songserm-ubt:~/Dropbox/projects/git-dummy/boulder$ git status
# On branch master
# Your branch is ahead of 'origin/master' by 3 commits.
#
# 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: folsom
#
no changes added to commit (use "git add" and/or "git commit -a")
“Changes not staged for commit:” means that if you do a git commit
w/o filename, it won’t commit these files.
It’s because these files are in working tree (not yet in stagging tree)
songserm@songserm-ubt:~/Dropbox/projects/git-dummy/boulder$ git help commit
songserm@songserm-ubt:~/Dropbox/projects/git-dummy/boulder$ git add folsom
songserm@songserm-ubt:~/Dropbox/projects/git-dummy/boulder$ git status
# On branch master
# Your branch is ahead of 'origin/master' by 3 commits.
#
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# modified: folsom
#
Doing git add filename
on a “modified” file will just add this not-staged file to a stagging tree
Warning: removing “modified” file (not a newly added one) in “Changes to be committed” using $ git rm --cache
will just “completely” remove the file’s content from the index tree (i.e. stagging tree)
songserm@songserm-ubt:~/Dropbox/projects/git-dummy/boulder$ git status
# On branch develop
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# modified: folsom
songserm@songserm-ubt:~/Dropbox/projects/git-dummy/boulder$ git rm --cache folsom
rm 'folsom'
songserm@songserm-ubt:~/Dropbox/projects/git-dummy/boulder$ git status
# On branch develop
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# deleted: folsom <<<< watch out for this, it's gonna delete your file
To undo the above, just git add
it again
songserm@songserm-ubt:~/Dropbox/projects/git-dummy/boulder$ git add folsom
songserm@songserm-ubt:~/Dropbox/projects/git-dummy/boulder$ git status
# On branch develop
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# modified: folsom <<<< it's back!!!
If you really want to remove “modified” file, use git reset -- <filename>
instead
songserm@songserm-ubt:~/Dropbox/projects/git-dummy/boulder$ git reset -- folsom
Unstaged changes after reset:
M folsom
M Gemfile.lock
M features/application/group/folsom.feature
M features/application/folsom/folsom_security.feature
M features/applicationfolsom/step_definitions/folsom_security_steps.rb
songserm@songserm-ubt:~/Dropbox/projects/git-dummy/boulder$ git status
# On branch develop
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
#
# 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: folsom <<<< it's back down to unstagged area
# modified: Gemfile.lock
# modified: features/application/group/folsom.feature
# modified: features/application/folsom/folsom_security.feature
# modified: features/application/folsom/step_definitions/folsom_security_steps.rb
#