1

Yesterday my teammate accidentally has committed a bad change leaking some credentials during the merge (a rough reconstruction):

# bad commit reconstruction
$ git pull
... no automatic merge happened ...
... some manual merge goes here ...
$ git add .                     # instead of `git add src`
$ git commit -m "merged"

and then committed another non-merge good change, but didn't push the changes:

# good commit reconstruction
... edit ...
$ git add .
$ git commit -m "foo bar"

I would like to modify the bad commit so the credentials could not be pushed to the remote repository. Since local commits are not pushed yet, first of all, I tried this solution using git rebase --interactive HEAD~2 (an old SVN-user hoping to rebase these bad and good revisions only), but it seems not to work showing more commits than expected (the ones that have been pulled) and fully omitting that bad commit. As far as I understand it does not work because of the merge. The current tree is as follows:

* GOOD [master]
|    
* merge + BAD
|\
| |
| * pulled [remote/origin/master]
| |   
| * pulled
| |   
| * pulled
| |   
| * pulled

How can I modify the bad commit excluding the files containing sensitive data so it could become a good commit as well and ready to push?

Community
  • 1
  • 1
Lyubomyr Shaydariv
  • 20,327
  • 12
  • 64
  • 105

1 Answers1

1

In order to preserve the merge created by the git pull, you can do:

git rebase -p @~2

The git rebase -p does preserve the merge commits it rebase.

-p
--preserve-merges

Instead of ignoring merges, try to recreate them.

This uses the --interactive machinery internally, but combining it with the --interactive option explicitly is generally not a good idea unless you know what you are doing (see BUGS below).

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250