How to remove improper commits from a remote branch?

Asked

Viewed 141 times

1

The company I work for hires some interns who take care of tasks small of various languages and different parts of the program (in order to enable them), but recently one of our interns made some commits from one branch into another in our remote repository, in order not to exclude the branch, recreate it and make the changes in some commits to make up this, I wonder if there is any method of:

  • "Rewrite" the commits, ignoring those who has no branch nexus, remaking the remote branch history.
  • Save commit changes to the wrong branch so that in the future they are placed in the right branch
  • Keep history with changes in date and time

I’m working with Bitbucket and Tortoisegit.

1 answer

3


It seems to me a case where revert and cherry-pick can be used well, without branches being so different from each other.

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

Then still on the wrong branch do: git revert <hash> for each in reverse order (from the latest to the oldest). This will cause the code to be removed from the wrong branch without rewriting the history, keeping the changes as they were - it will create a commit reversing each wrong one.

When you have the new branch where changes should be applied, just do 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 on the other branch.

  • I think it’s worth putting an addendum to deadly commits, like sending the bank password unintentionally in the file

  • The question talked about keeping the history and keeping the changes, it does not seem to be the case. The only really safe thing to do when sending the password from the GIT database is to change the password of the database.

  • Well, that’s true, but sometimes we fool around and need to rewrite history. I know this is beyond what was asked by @Paz, but it’s something I always find important to quote, by neurosis even. Github has a post on this subject

Browser other questions tagged

You are not signed in. Login or sign up in order to post.