$ git init
Initialized empty Git repository in .git/
$ git add .
$ git status
# On branch master
#
# Initial commit
#
# Changes to be committed:
# (use "git rm --cached <file>..." to unstage)
#
# new file: test1
# new file: test2
#
$ git commit
Created initial commit d80fdfb: Test
2 files changed, 92 insertions(+), 0 deletions(-)
create mode 100644 test1
create mode 100644 test2
$ git log
commit d80fdfb6486e37e4f0a56d0af67b217c72857531
Author: dahlolz <dahlolz@.(none)>
Date: Sat Dec 26 19:13:26 2009 -0800
Test
# I've added a new file "stuff" to the tree. Let's see what happened.
$ git status
# On branch master
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# stuff
nothing added to commit but untracked files present (use "git add" to track)
$ git add stuff
$ git commit
Created commit 12b6eb8: Test2
0 files changed, 0 insertions(+), 0 deletions(-)
create mode 100644 stuff
$ git log
commit 12b6eb8cbcf0986266a479d3383481e126019b25
Author: dahlolz <dahlolz@.(none)>
Date: Sat Dec 26 19:15:52 2009 -0800
Test2
commit d80fdfb6486e37e4f0a56d0af67b217c72857531
Author: dahlolz <dahlolz@.(none)>
Date: Sat Dec 26 19:13:26 2009 -0800
Test
# Now I deleted the tracked file stuff.
$ git status
# On branch master
# Changed but not updated:
# (use "git add/rm <file>..." to update what will be committed)
#
# deleted: stuff
#
no changes added to commit (use "git add" and/or "git commit -a")
$ git commit -a
Created commit b36a76c: Test3
0 files changed, 0 insertions(+), 0 deletions(-)
delete mode 100644 stuff
$ git log
commit b36a76c47efa8fe30b921e6b3c8cdfd898bd0259
Author: dahlolz <dahlolz@.(none)>
Date: Sat Dec 26 19:16:16 2009 -0800
Test3
commit 12b6eb8cbcf0986266a479d3383481e126019b25
Author: dahlolz <dahlolz@.(none)>
Date: Sat Dec 26 19:15:52 2009 -0800
Test2
commit d80fdfb6486e37e4f0a56d0af67b217c72857531
Author: dahlolz <dahlolz@.(none)>
Date: Sat Dec 26 19:13:26 2009 -0800
Test
# I want to revert the log but keep the working tree (e.g., if I've changed
# something, I don't want to lose my changes).
$ git reset --soft HEAD^
$ git log
commit 12b6eb8cbcf0986266a479d3383481e126019b25
Author: dahlolz <dahlolz@.(none)>
Date: Sat Dec 26 19:15:52 2009 -0800
Test2
commit d80fdfb6486e37e4f0a56d0af67b217c72857531
Author: dahlolz <dahlolz@.(none)>
Date: Sat Dec 26 19:13:26 2009 -0800
Test
# The last commit message (Test3) is gone.
# What's it look like now?
$ git status
# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# deleted: stuff
#
# The file "stuff" has still been deleted.
# Using a soft reset let's me change the commit.
$ git commit -a
Created commit 9ccb352: Test3
0 files changed, 0 insertions(+), 0 deletions(-)
delete mode 100644 stuff
$ git status
# On branch master
nothing to commit (working directory clean)
$ git log
commit 9ccb352669dee2f091cf33d10fbc56ee0f901185
Author: dahlolz <dahlolz@.(none)>
Date: Sat Dec 26 19:16:50 2009 -0800
Test3
commit 12b6eb8cbcf0986266a479d3383481e126019b25
Author: dahlolz <dahlolz@.(none)>
Date: Sat Dec 26 19:15:52 2009 -0800
Test2
commit d80fdfb6486e37e4f0a56d0af67b217c72857531
Author: dahlolz <dahlolz@.(none)>
Date: Sat Dec 26 19:13:26 2009 -0800
Test
# Let's try a hard reset, which will now reset files as well.
# The commit "Test" added the files test1 and test2.
# The commit "Test2" added the file stuff.
# The commit "Test3" deleted the file stuff.
$ git reset --hard HEAD^
HEAD is now at 12b6eb8... Test2
$ git reset --hard HEAD^
HEAD is now at d80fdfb... Test
$ ls
test1 test2
# This is the initial commit, and stuff doesn't exist.