2

I need a little help. I need to remove a commit (in this case it was a merge that I've merged into this branch using --no-ff parameter). As you can see my git log below, I need to get off the hash dc7f605a7ac7af66370ce7cd5e4a1258872325e5 This is the situation:

commit 56c7a1283518b58cc3c90a84028357f9f4c61c74
Merge: d7bca64 938b607
Author: Luiz Kim Dias <luizkim@gmail.com>
Date:   Wed Aug 6 18:28:52 2014 -0300

    Merge branch 'develop' of bitbucket.org:casperlibero/genet into develop

commit d7bca6495b593af156850db17beb27c0e81f6243
Merge: b3606e2 cc04dc2
Author: Luiz Kim Dias <luizkim@gmail.com>
Date:   Wed Aug 6 18:28:21 2014 -0300

    Merge branch 'integration-204' into develop

commit cc04dc2010db5daa717819503fcbacbc7b4b5425
Merge: 647eec7 0700fd7
Author: Luiz Kim Dias <luizkim@gmail.com>
Date:   Wed Aug 6 18:26:32 2014 -0300

    Merge branch 'task-204' into integration-204

commit 0700fd7e831c33304c72557a489e379af8736842
Author: lkdias <luizkim@gmail.com>
Date:   Wed Aug 6 18:24:06 2014 -0300

    Removendo mais algumas pastas e adicionando um .gitignore para alguns casos

commit 938b60735259f32b2bd5f55c7095d055ebcd6fcc
Merge: 5bc8fd0 1e9bfdb
Author: Édipo Rebouças <edcosta@fcl.com.br>
Date:   Wed Aug 6 16:16:44 2014 -0300

    Merge branch 'integration-178' into develop

commit 1e9bfdb8918b3a70e2ace0ceee4c5e7115d746bd
Merge: b3606e2 041288a
Author: Édipo Rebouças <edcosta@fcl.com.br>
Date:   Wed Aug 6 16:16:13 2014 -0300

    Merge branch 'ecr-card-178' into integration-178

commit 041288a55dd390045cea4da8e778685874c3ae84
Author: Édipo Rebouças <edcosta@fcl.com.br>
Date:   Wed Aug 6 16:15:08 2014 -0300

    correções com chars estranhos

commit e5b7a1f0edf020102abade3f055fe84c50e73bdd
Author: Fábio Garbini <fabio@garbini.net>
Date:   Wed Aug 6 15:44:57 2014 -0300

    Inclusão de botao para copiar link, inclusao de icone da rede social a qual a foto pertence.

commit b6c32dda3e49aff8010d3ea2b43083ba7154ec7f
Author: Édipo Rebouças <edcosta@fcl.com.br>
Date:   Wed Aug 6 14:15:33 2014 -0300

    adicionado campo serviço

// I would like just to get off this hash and left all of other commits safely.
**commit dc7f605a7ac7af66370ce7cd5e4a1258872325e5**
Merge: 0636f68 647eec7
Author: Luiz Kim Dias <luizkim@gmail.com>
Date:   Wed Aug 6 13:28:38 2014 -0300

    Merge branch 'master' into task-204

commit b3606e2e8e960c8aeae3f23f3e1f4492b22de219
Merge: 2a1566e 95b350b
Author: Luiz Kim Dias <luizkim@gmail.com>
Date:   Wed Aug 6 12:27:48 2014 -0300

    Merge branch 'fg-card-172' into develop

commit 647eec7be0b734a741ec8f1b91292c8f13576aaa
Merge: c77ab89 574c8af
Author: Luiz Kim Dias <luizkim@gmail.com>
Date:   Wed Aug 6 11:33:34 2014 -0300

    Merge branch 'release-v1.43.0'

My question is: Is it possible to remove that specific commit maintaining all of those other commits safe? I say remove this commit meaning exclude all chances that I've done on this one.

  • If you're not sharing your commits with other people, then you have the option of using either [hard reset](http://stackoverflow.com/a/2389423/456814) (and re-merging the `genet/develop` branch), followed by a force push, or you can use [a revert](http://stackoverflow.com/a/6217372/456814). If you're sharing your commits with other people, and they're unwilling to deal with a force push, then your only option is to use the `git revert`, since it won't modify existing history like a hard reset will. –  Aug 09 '14 at 03:28
  • 1
    Here's another tip, next time you want help with your Git problem, please show the output of `git log --graph --oneline --decorate` instead, it's much easier to read and visualize your commit graph that way. –  Aug 09 '14 at 03:31

1 Answers1

0

Try git revert HASH where HASH is the hash of the commit your want to remove.

Essentially, git revert makes a new commit that exactly cancels out the previous commit. I know this works on commits in the same branch, and I would assume it would work perfectly fine on a merge commit.

jamesthollowell
  • 1,550
  • 15
  • 21
  • `git revert ` by itself won't work for merge commits. –  Aug 09 '14 at 03:31
  • Why not? Doesn't a merge commit act the same as a regular commit? PS. I am not a git wizard by any means, but I just had a similar problem the other day, so I thought I would share what I leaned. – jamesthollowell Aug 09 '14 at 14:54
  • Try it on a merge commit and see what happens. –  Aug 09 '14 at 17:17
  • @Cupcake you should turn your comment into an answer. It is more fleshed out even as a comment than my answer is. – jamesthollowell Aug 09 '14 at 18:10
  • I closed this question as a duplicate for a reason `:/` –  Aug 09 '14 at 18:12