Skip to content
Abhik B Pramanik edited this page Aug 11, 2011 · 17 revisions

Here's the process of commiting changes to the local repository:

  1. Let's makes some changes:

    % echo "Hope you enjoy the tutorial." >> README
    % echo "\nTo cleanup the workspace:\n\nrm *.class" >> INSTALL
    
  2. Run git status in 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")
    
  3. Despite there being changes, if you run git commit nothing 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")
    
  4. 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
    
  5. 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
    #
    
  6. Now commit via git commit. This will open your $EDITOR and 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")
    
  7. 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.

Clone this wiki locally