Make delicious recipes!

Lifecycle of a Git file



A file in git goes through the following stages:



git add puts a snapshot of the file to the staging area.
Further modification to the file will not be committed with git commit unless a git add is done again.


git diff compares local file to the staged file.
git diff --staged compares staged file to the committed file.
=> if you have staged all your changes, then git diff will give no output but git diff -- staged will show you all the changes.


Removing a file

rm foo
git rm foo
git commit foo

If you accidentally staged a file, it can be removed from the staging area by
git rm --cahced foo
This keeps the file in your local directory but removes it from staging area.


Moving a file

git mv src.txt dest.txt
git considers moving a file as renaming a file.
This is useful because the file history is preserved on rename.







Like us on Facebook to remain in touch
with the latest in technology and tutorials!


Got a thought to share or found a
bug in the code?
We'd love to hear from you:

Name:
Email: (Your email is not shared with anybody)
Comment:

Facebook comments:

Site Owner: Sachin Goyal