0

We are working on a single branch with about 20 developers. Yesterday someone accidentally messed up with the auto merge commit.

He had a pull taken 24 hours(span-1) before committing. After committing and taking a pull he accidentally reverted all files shown in the auto merge commit believing that they shouldn't be committed as he had not changed those files. After that he committed the auto merge and pushed it. After 24 hours(span-2) of this push we recognized this issue.

Now the problem is, in span-1 we have around 25 commits by 10 developers and similar in span-2. The changes are on same/different files by same/different developers.

We tried cherry picking but it asks for conflict resolution which is definitely not possible in our case as many developers are involved.

Is there a way to easily solve this problem. Basically I want to delete that merge commit. If required we can even delete the actual commit done by that developer between span-1 and span-2. Having these changes in history will not be a problem. We just want a clean repository.

Note: The question here doesn't address my specific problem. It is a general question on deleting git commits. Also I am not interested in deleting/rewriting history. We just want the rolled back changes due to bad merge to be available on the remote repository without having to resolve merge conflicts

Community
  • 1
  • 1
Mukund Jalan
  • 673
  • 7
  • 24
  • Possible duplicate of [Delete commits from a branch in Git](http://stackoverflow.com/questions/1338728/delete-commits-from-a-branch-in-git) – Andrew C Jan 07 '16 at 18:07

1 Answers1

0

Is there a way to easily solve this problem.
Basically I want to delete that merge commit


reset

  # reset the branch to any given commit
  git reset HEAD <sha-1>

  # push the branch with the -f flag = rebase
  # 
  # THIS IS VERY DANGEROUS, ITS REBASE. 
  # all the developers will have to re-clone the project
  git push -f origin <branch>
  

revert (create a commit with the reverse patch)

This way you don't rewrite any history.

On the other hand, if you've published the work, you probably don't want to reset the branch, since that's effectively rewriting history.

In that case, you could indeed revert the commits.

# This will create X separate revert commits 
# (undo the original commit changes)
# if the revert is merge you will have to supply the parent number as well `-m`
git revert <sha1> <sha1> <sha1> ...

# It also takes ranges. This will revert the last two commits:
git revert HEAD~X..HEAD~Y

# Reverting a merge commit
git revert -m 1 <merge_commit_sha>

The git-revert manpage actually covers a lot of this in its description.
Another useful link is this git-scm.com blog post discussing git-revert.

If you decide you didn't want to revert after all, you can revert the revert (as described here) or reset back to before the revert (see the previous section).


git filter-branch

Lets you rewrite Git revision history by rewriting the branches mentioned in the , applying custom filters on each revision.

Those filters can modify each tree (e.g. removing a file or running a perl rewrite on all files) or information about each commit. Otherwise, all information (including original commit times or merge information) will be preserved.

Community
  • 1
  • 1
CodeWizard
  • 92,491
  • 19
  • 110
  • 133
  • What steps could fit in for my use case? I don't find this information much relevant – Mukund Jalan Jan 07 '16 at 20:14
  • reset/revert any of them – CodeWizard Jan 07 '16 at 20:24
  • rebasing is not an option as it will disrupt the whole history. Trying revert is not helping as I get no way where the lost changes in the merge could be brought back. I followed the steps as in the said git blog but cannot get the lost changes back in merge – Mukund Jalan Jan 07 '16 at 20:40