0

So I've got a situation where several sprints ago we had a bad set of check-in's from another team. Why they have access to our code, is something else I'll be looking into BUT what I have to do now is remove their changes. They were at least named well so I know which ones they were. The approach I'm considering is to rewind back to just before and then merge everything going forward EXCEPT those changes. Is there a better approach? Is there a way I can specify a range of changes or is there a way to do an exclude?

user447607
  • 5,149
  • 13
  • 33
  • 55
  • No sure is your looking for https://stackoverflow.com/questions/6294355/git-how-to-exclude-files-from-merging for exclude way add to ignore git file to no been staged or merged the next time. –  Oct 27 '17 at 15:40
  • Sounds like a good solution to me. Though I would suggest `git rebase` rather than git merge after you've rewound. There are variants of `git rebase` that will probably do all of what you want too without having to do the initial rewind, but just add extra complexity for no real benefit. – Mort Oct 27 '17 at 15:47

1 Answers1

2

The approach I'm considering is to rewind back to just before and then merge everything going forward EXCEPT those changes.

Except if I really don't understand what you plan to do, no that's not possible with git to do a partial merge.

Is there a better approach? Is there a way I can specify a range of changes or is there a way to do an exclude?

With git, there is often multiple possibilities:

  1. Directly on the branch containing the bad commits, use the command git revert on each commit starting from the more recent (creating a revert commit each time or one for all the commits reverted).

1bis. Better, You could, revert à range of commits:

https://stackoverflow.com/a/4992711/717372

It could work quite well if you don't have conflicts because files changed have not been changed since then.

If you have conflicts, you could try :

2.

  • create a branch called something like 'revert-bad-commits' on the last bad commit.
  • create one or more revert commits like described in the solution 1. (you won't have conflicts in this case!)
  • merge this new branch into your branch (you will surely have conflicts but their is a probability that they will be easier to solve, and in one time)
Philippe
  • 28,207
  • 6
  • 54
  • 78