Skip to content

Instantly share code, notes, and snippets.

@henrahmagix
Created July 20, 2016 15:56
Show Gist options
  • Save henrahmagix/d101159dabe56d36d0bd74b3d096eb09 to your computer and use it in GitHub Desktop.
Save henrahmagix/d101159dabe56d36d0bd74b3d096eb09 to your computer and use it in GitHub Desktop.
Git Presentation Demo: commits
git init
git commit --allow-empty -m 'Initial commit'
# Commit a file
echo 'foo' > a
git add a
git commit -m 'Commit'
# Commit another file with the same contents
echo 'foo' > b
git add b
git commit -m 'Commit'
# See the git hash objects
git ls-tree HEAD # They're the same because we're looking at commit objects
git log --oneline # They're not the same because we're looking at tree objects
# Change a commit
echo 'bar' >> b
git add b
git diff --cached
git commit --amend -m 'Change'
git log --oneline # The original commit is gone
# But we can still see it
git show <hashfrombefore>
# Lets "undo" the amend
git reflog show
git reset --hard HEAD@{1}
git log --oneline # The original commit is back, the new commit is gone
# But we can still see it
git show <amendedhash>
# more info http://stackoverflow.com/a/28881708/3150057
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment