I'm new to git, coming from SVN world. So far, it seems a lot more useful, but I am still working out the kinks.
Currently, my workflow is like this:
make changes > git add . > git commit > enter log message
What I don't understand is why I seem to have to add all of my files before I commit. They are under version control already? Why does git commit tell me there are no changes added to the commit, but also point out that I have modified files? It says "Changed but not updated:". What does this mean??
Sorry if this is easy, I feel like I am missing some overarching point
You have to git add even with plain git to stage files for commit. It's just that if you explicitly list what you want to commit with git commit , it does staging for you. But if you don't specify list of files to commit, then git commit only commits files you staged with git add .
Without adding any files, the command git commit won't work. Git only looks to the staging area to find out what to commit. Staging, or adding, files, is possible through the command line, and also possible with most Git interfaces like GitHub Desktop by selecting the lines or files that you'd like to stage.
Committing in git can be a multiple step process or one step depending on the situation. This situation is where you have multiple file updated and wants to commit: You have to add all the modified files before you commit anything. with this you have to add the message for this commit.
The general rule (for both scenarios) would be: Commit as often as possible. If you think "it's not ready yet" (because it'll break the build or simply isn't done yet) then create a branch and commit to that branch but make sure you do commit.
This allows you to separate commits by edits. If you only want to commit these files now, under one commit, and then these next files now, under a second commit, you could do:
git add files_under_one_topic git commit -m "this is about one thing" git add files_left_over_to_commit_about_a_completely_different_topic git commit -m "this is about another thing."
Git works by using a "staging" area where you prepare what you are going to bundle together as a commit. So, you decided what set of changes you want to commit (e.g. all or a subset), you add them to the staging area, and then you commit what's in the staging area.
When you invoke git status
, it shows you what has been added to the staging area (i.e. "Changes to be committed"), what has been modified among the files git is tracking (i.e. Changed but not updated"), and any new files that you've never added before (i.e. Untracked files).
If you want to just commit stuff that you've changed, but not include newly created files you can use git commit -a -m "Comment for modified files already under source control."
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