Skip to content

Instantly share code, notes, and snippets.

@ifyouseewendy
Last active August 29, 2015 14:06
Show Gist options
  • Save ifyouseewendy/011f94ef20413f7a2df4 to your computer and use it in GitHub Desktop.
Save ifyouseewendy/011f94ef20413f7a2df4 to your computer and use it in GitHub Desktop.
some useful commands

How to revert all the commits involved by a merge?

git revert {merge SHA} -m 1

ref -m, --mainline <n> parent number

eg.

➜  wendi-mac ~/tmp/demo (master)                                                                   (ruby-2.0.0-p353)
➜  ls
a     b     c     hello

➜  wendi-mac ~/tmp/demo (master)                                                                   (ruby-2.0.0-p353)
➜  git h
* 3755618 2014-09-25 Add c [wendi]
*   0eb90e2 2014-09-25 Merge branch 'test' [wendi]
|\  
| * eb2a701 2014-09-25 Add b [wendi]
| * 1754b68 2014-09-25 Add a [wendi]
|/  
* d2e1b51 2014-09-25 Init [wendi]

➜  wendi-mac ~/tmp/demo (master)                                                                   (ruby-2.0.0-p353)
➜  git revert 0eb90e2 -m 1
[master 808268d] Revert "Merge branch 'test'"
 2 files changed, 0 insertions(+), 0 deletions(-)
 delete mode 100644 a
 delete mode 100644 b

➜  wendi-mac ~/tmp/demo (master)                                                                   (ruby-2.0.0-p353)
➜  ls
c     hello

How to do quick fix up one previous commit?

$ git commit --fixup={SHA}
$ git rebase -i --autosquash {SHA}^

ref

  • --fixup= Construct a commit message for use with rebase --autosquash. The commit message will be the subject line from the specified commit with a prefix of "fixup! ". See git-rebase(1) for details.

  • --squash= Construct a commit message for use with rebase --autosquash. The commit message subject line is taken from the specified commit with a prefix of "squash! ". Can be used with additional commit message options (-m/-c/-C/-F). See git-rebase(1) for details.

eg.

➜  wendi-mac ~/tmp/demo (master) 
➜  echo 'a' > a; git add .; git ci -m 'Add a';
➜  wendi-mac ~/tmp/demo (master) 
➜  echo 'b' > b; git add .; git ci -m 'Add b';
➜  wendi-mac ~/tmp/demo (master)                                                                   (ruby-2.0.0-p353)
➜  git h
* 16ed5a8 2014-09-25 Add b [wendi]
* a8349ef 2014-09-25 Add a [wendi]
➜  wendi-mac ~/tmp/demo (master)                                                                   (ruby-2.0.0-p353)
➜  echo 'aaa' > a; git add .; git ci --fixup=a8349ef;
➜  wendi-mac ~/tmp/demo (master)                                                                   (ruby-2.0.0-p353)
➜  git h
* 3f26d33 2014-09-25 fixup! Add a [wendi]
* 16ed5a8 2014-09-25 Add b [wendi]
* a8349ef 2014-09-25 Add a [wendi]
➜  wendi-mac ~/tmp/demo (master)                                                                   (ruby-2.0.0-p353)
➜  git rebase -i --autosquash a8349ef^
   # pick a8349ef Add a
   # fixup 3f26d33 fixup! Add a
   # pick 16ed5a8 Add b
[detached HEAD c5b89b3] Add a
 1 file changed, 1 insertion(+)
 create mode 100644 a
Successfully rebased and updated refs/heads/master.
➜  wendi-mac ~/tmp/demo (master)                                                                   (ruby-2.0.0-p353)
➜  git h
* 41b93cb 2014-09-25 Add b [wendi]
* c5b89b3 2014-09-25 Add a [wendi]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment