lab 19 Amending Commits

Goals

Change the program then commit 01

Add an author comment to the program.

File: hello.rb

# Default is World
# Author: Ismail Dhorat
name = ARGV.first || "World"

puts "Hello, #{name}!"

Execute:

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

Oops, Should have an Email 02

After you make the commit, you realize that any good author comment should have an email included. Update the hello program to include an email.

File: hello.rb

# Default is World
# Author: Ismail Dhorat (ismail@somewhere.com)
name = ARGV.first || "World"

puts "Hello, #{name}!"

Amend the Previous Commit 03

We really don’t want a separate commit for just the email. Let’s amend the previous commit to include the email change.

Execute:

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

Output:

$ git add hello.rb
$ git commit --amend -m "Add an author/email comment"
[master 273edac] Add an author/email comment
 1 file changed, 2 insertions(+), 1 deletion(-)

Review the History 04

Execute:

git hist

Output:

$ git hist
* 273edac 2013-10-06 | Add an author/email comment (HEAD, master) [Ismail Dhorat]
* 9efd33e 2013-10-06 | Added a comment (v1) [Ismail Dhorat]
* 8b9a1c6 2013-10-06 | Added a default value (v1-beta) [Ismail Dhorat]
* f6f4d6b 2013-10-06 | Using ARGV [Ismail Dhorat]
* f98d857 2013-10-06 | First Commit [Ismail Dhorat]

We can see the original “author” commit is now gone, and it is replaced by the “author/email” commit. You can achieve the same effect by resetting the branch back one commit and then recommitting the new changes.

Table of Contents