Skip to content

Instantly share code, notes, and snippets.

@cesarkawakami
Last active October 26, 2017 18:47
Show Gist options
  • Save cesarkawakami/6f36d74928327d97e92db9145f3d3ca8 to your computer and use it in GitHub Desktop.
Save cesarkawakami/6f36d74928327d97e92db9145f3d3ca8 to your computer and use it in GitHub Desktop.
$ git init .
Initialized empty Git repository in /home/kawakami/temp/test/.git/
$ touch init
$ git add init
$ git commit -m 'initial commit'
[master (root-commit) 4c0c59e] initial commit
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 init
$ git commit -m 'empty commit' --allow-empty
[master a9a6943] empty commit
$ touch somefile
$ git add somefile
$ git commit -m 'nonempty on top'
[master f2fe53a] nonempty on top
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 somefile
$ git lg
* f2fe53a - (HEAD -> master) nonempty on top (1 second ago) <Cesar Kawakami>
* a9a6943 - empty commit (14 seconds ago) <Cesar Kawakami>
* 4c0c59e - initial commit (24 seconds ago) <Cesar Kawakami>
$ git show HEAD^
commit a9a694399502707e53e8cdd213c81b2e04f8d1c2
Author: Cesar Kawakami <kawakami@fb.com>
Date: Thu Oct 26 11:44:03 2017 -0700
empty commit
$ git rebase -i 4c0c59e
Stopped at a9a6943... empty commit
You can amend the commit now, with
git commit --amend
Once you are satisfied with your changes, run
git rebase --continue
$ git commit --amend
interactive rebase in progress; onto 4c0c59e
Last command done (1 command done):
e a9a6943 empty commit
Next command to do (1 remaining command):
pick f2fe53a nonempty on top
You are currently editing a commit while rebasing branch 'master' on '4c0c59e'.
No changes
You asked to amend the most recent commit, but doing so would make
it empty. You can repeat your command with --allow-empty, or you can
remove the commit entirely with "git reset HEAD^".
$ git commit --amend --allow-empty
[detached HEAD 8776c75] empty commit edited
Date: Thu Oct 26 11:44:03 2017 -0700
$ git rebase --continue
Successfully rebased and updated refs/heads/master.
$ git lg
* d469064 - (HEAD -> master) nonempty on top (2 seconds ago) <Cesar Kawakami>
* 8776c75 - empty commit edited (9 seconds ago) <Cesar Kawakami>
* 4c0c59e - initial commit (87 seconds ago) <Cesar Kawakami>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment