1

A coworker recently pushed 4 commits to our remote repository that are not desirable. I would now like to overwrite those last 4 commits with my code and do not want to mess with all the merge conflicts.

To be clear, the 4 commits to overwrite are the last 4 commits on the branch. Nothing relies on them.

Should I just force push? What is the best way to do this?

Eric Cochran
  • 8,414
  • 5
  • 50
  • 91

1 Answers1

3

Your co-worker can use git revert functionality which creates a new commit which is reverse of the changes introduced in the incorrect commits. He or she can push this new commit to the repo and others can pull in the changes.

You can then rebase your commits on the new commit from git revert.

rogue-one
  • 11,259
  • 7
  • 53
  • 75
  • Hypothetically, let's say the coworker is on vacation. Any other way to do this? – Eric Cochran Aug 11 '14 at 01:22
  • 1
    @NightlyNexus may-be create a new clone do the revert on the branch and push it, ofcourse if the repo is small enough to clone. – rogue-one Aug 11 '14 at 01:26
  • 1
    @NightlyNexus That will still work. `git revert` undoes a commit, regardless of whether or not you are the original comitter. – Nick McCurdy Aug 11 '14 at 01:26
  • @NicolasMcCurdy Git will tell me I have to merge first. That is what I am trying to avoid. – Eric Cochran Aug 11 '14 at 01:27
  • @NicolasMcCurdy but Nightly's Branch already has new commits and hence wouldn't he have to merge or rebase first to revert it? – rogue-one Aug 11 '14 at 01:28
  • @mig-foxbat That's a really good point. I could, but I think, in my case, that would be a long task. Thanks for the great ideas, though! I'll probably force push. – Eric Cochran Aug 11 '14 at 01:29