-
Notifications
You must be signed in to change notification settings - Fork 15
Committing changes
Here's the process of commiting changes to the local repository:
-
Let's makes some changes:
% echo "Hope you enjoy the tutorial." >> README % echo "\nTo cleanup the workspace:\n\nrm *.class" >> INSTALL -
Run
git statusin the workspace to confirm that git picked up the changes.% git status # On branch master # Changed but not updated: # (use "git add <file>..." to update what will be committed) # (use "git checkout -- <file>..." to discard changes in working directory) # # modified: INSTALL # modified: README # no changes added to commit (use "git add" and/or "git commit -a") -
Despite there being changes, if you run
git commitnothing should happen.% git commit -m "This shouldn't work" # On branch master # Changed but not updated: # (use "git add <file>..." to update what will be committed) # (use "git checkout -- <file>..." to discard changes in working directory) # # modified: INSTALL # modified: README # no changes added to commit (use "git add" and/or "git commit -a") -
You'll need to stage the changes for the commit via
git add. Let's stage just the INSTALL change.% git add INSTALL % git status # On branch master # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # modified: INSTALL # # Changed but not updated: # (use "git add <file>..." to update what will be committed) # (use "git checkout -- <file>..." to discard changes in working directory) # # modified: README -
It's important to note that you staged the change and not the file. Any more changes you make to INSTALL will not be staged.
% echo "\nAnother change." >> INSTALL % git status # On branch master # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # modified: INSTALL # # Changed but not updated: # (use "git add <file>..." to update what will be committed) # (use "git checkout -- <file>..." to discard changes in working directory) # # modified: INSTALL # modified: README # -
Now commit via
git commit. This will open your$EDITORand allow you to add a message. You can also add a message via-m <message>and skip opening the editor.% git commit -m "Adding clean instructions to INSTALL" [master 8e89ada] Adding clean instructions to INSTALL 1 files changed, 4 insertions(+), 0 deletions(-) % git status # On branch master # Your branch is ahead of 'origin/master' by 1 commit. # # Changed but not updated: # (use "git add <file>..." to update what will be committed) # (use "git checkout -- <file>..." to discard changes in working # directory) # # modified: INSTALL # modified: README # no changes added to commit (use "git add" and/or "git commit -a") -
Notice that when you run git status, it mentions
Your branch is ahead of 'origin/master' by 1 commit. The committed change is now in your local repository but still needs to be pushed to the remote repository. See Pushing changes to origin/master.