19. Changing commits

Goals

  • To learn how to modify an already existing commit

01 Change the page and commit

Post an author comment on the page.

File: hello.html

<!-- Author: Marina Pushkova -->
<html>
  <head>
  </head>
  <body>
    <h1>Hello, World!</h1>
  </body>
</html>

Run:

git add hello.html
git commit -m "Add an author comment"

02 Oops... email required

After making the commit you understand that every good comment should include the author's email.Refresh the hello page, to provide an email.

File: hello.html

<!-- Author: Marina Pushkova (marina@githowto.com) -->
<html>
  <head>
  </head>
  <body>
    <h1>Hello, World!</h1>
  </body>
</html>

03 Change the previous commit

We do not want to create another commit for e-mail. Let us change the previous commit and add an e-mail address.

Run:

git add hello.html
git commit --amend -m "Add an author/email comment"

Result:

$ git add hello.html
$ git commit --amend -m "Add an author/email comment"
[master 6a78635] Add an author/email comment
 1 files changed, 2 insertions(+), 1 deletions(-)

04 View history

Run:

git hist

Result:

$ git hist
* 6a78635 2011-03-09 | Add an author/email comment (HEAD, master) [Marina Pushkova]
* fa3c141 2011-03-09 | Added HTML header (v1) [Marina Pushkova]
* 8c32287 2011-03-09 | Added standard HTML page tags (v1-beta) [Marina Pushkova]
* 43628f7 2011-03-09 | Added h1 tag [Marina Pushkova]
* 911e8c9 2011-03-09 | First Commit [Marina Pushkova]

The new "author/email" commit replaces the original "author" commit. The same effect can be achieved by resetting the last commit in the branch, and recommitting new changes.

SVN?
© 2011-2014 Git How To. All rights reserved / Contact us