remove an improper commit from history but keep current changes in files

Asked

Viewed 425 times

2

I cloned a remote repository and soon after that I had to pull some files from a specific branch and it looks like it was merged (unintentionally) into the master itself, then created a new branch (apart from master) with the command git checkout -b nova_branch, I made some modifications and then gave a push from that new branch to the remote repository (it didn’t exist remotely), and it happened that in addition to my work it was also sent the branch history I had done given a pull (which improper merge occurred), just that I didn’t want it to happen, how can I remove this branch that shouldn’t have been "shit" and remove it from the history/log, both local and remote, but keep the modifications of the last commits?

the log is like this:

69ddf1d09a108a5989a67e955273853c (HEAD) -> mais recente (commit com as modificações corretas)
3a39b68b00aaf809165adae9a5897f86 -> correções corrretas
c6d496b50e63c91cb40b970b568803a9 -> correções corretas
1da606decbfc2832a91af185dc0013c9 (master) -> commit "errado", o qual foi puxado de uma branch remota e que quero excluir da história/log.

I thought I’d use the reset --soft 1da606decbfc2832a91af185dc0013c9, that would be a good solution?

EDIT:

For better example, follow github image: inserir a descrição da imagem aqui circled in red are the histories that came from the branch I merged unintentionally and I want to remove.

1 answer

1

In your case, to disappear the unwanted commit from the history and remove the changes made by it, rebase your new branch:

git rebase -i 1da606^

So when the text editor opens, remove the first line from the file, which will be the unwanted commit, and save.

If there is conflict, resolve the conflict and continue git rebase --continue.

This will preserve the changes to your current branch, remove the changes from the 1da606 commit, and erase the history of the unwanted merge.

  • What does that mean at the end of the hash?

  • showed the commit list with "pick", but didn’t show the "merge" commit, is that right? , in this case, only displayed the 3 correct commits as I said above

  • 1

    is to refer to the first parent of the 1da606 commit. In general terms, the idea is to connect your branch directly to the main parent commit of the merge commit.

  • 1

    It should display the merge commit and you delete the line. You used the ^?

  • I didn’t know, I thought it was an abbreviation for not writing the whole hash, gave a conflict, had to settle with reset, but thanks

Browser other questions tagged

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