When you modify a file in your working directory, git tells you to use "git add" to stage.
When you add a new file to your working directory, git tells you to use "git add" to start tracking.
I am a bit confused about these 2 concepts because i assumed tracking a file for changes is different from staging it for commit
A staging step in git allows you to continue making changes to the working directory, and when you decide you wanna interact with version control, it allows you to record changes in small commits.
Tracked files are files that were in the last snapshot, as well as any newly staged files; they can be unmodified, modified, or staged. In short, tracked files are files that Git knows about.
If a particular version of a file is in the Git directory, it's considered committed. If it has been modified and was added to the staging area, it is staged.
Every project under the distributed version control system Git, goes through three stages — Modified, Staged, and Committed.
Git essentially has 4 main statuses for the files in your local repo:
git add <file>
, it becomes:git commit
, it becomes:git add
As you can see, a git add
will track untracked files, and stage any file.
Also: You can untrack an uncommited file with git rm --cached filename
and unstage a staged file with git reset HEAD <file>
Git has a concept known as 'the index'. To create a new commit, you fill the index with the contents you'd like to have in the next commit. That means that you have to explicitly tell Git which changes you want to appear in the next commit by using git add
. (git add -p
to add only single hunks)
It doesn't make a difference to Git whether you only update a file (»stage changes«) or if you add the full content of a new file (»start tracking a file«) – both times, all that Git's index sees is the addition of new changes
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With