How to remove undue commits from a remote branch?

1

The company in which you work hires some trainees who take care of small tasks of several languages and different parts of the program (in order to enable them), but recently one of our trainees did some commits of one branch in another in our remote repository, in order not to delete the branch, recreate it and make the changes in some commits to make it, I would like to know if there is any method of:

  • "Rewrite" the commits, ignoring those who has no connection with the branch, redoing the history of the remote branch.
  • Save the changes made to the commits in the wrong branch so that they will be placed in the correct branch in the future
  • Keep history with changes to the right date and time

I'm working with bitbucket and TortoiseGit.

    
asked by anonymous 26.04.2017 / 20:00

1 answer

3

It seems like a case where revert and cherry-pick can be well used, without the branches are not so different from each other.

Take the history of the commits hashes in the wrong branch and make a list.

Then even in the wrong branch, do: git revert <hash> for each in the reverse order (from the most recent oldest pro). This will cause the code to be removed from the wrong branch without rewriting the history, keeping the changes as they were - will create a commit by reversing each of the wrong ones.

When you have the new branch where the changes should be applied, just make git cherry-pick <hash> for each of the hashes in the right order (from the oldest most recent pro). This will apply the changes exactly as they were done in the other branch.

    
25.05.2017 / 12:48