Home > Back-end >  Undo git commit message in 2 different branches (develop and feature) after git push
Undo git commit message in 2 different branches (develop and feature) after git push

Time:07-06

do not want to break anything in the master branch.

  1. I forked a develop branch through below commands git checkout develop git pull upstream develop # pull the updates locally based on the git push origin develop # sync your local develop branch with

  2. accidentally made few commits in that develop branch then reverted back with below commits d3b229f9 (develop) Merge branch 'develop' of github.com:ROCmSoftwarePlatform/bench into develop 16daa203 Revert "kernel converter tool to create yaml file from lib 97e834cb kernel converter tool to create yaml file from lib"

  3. Created below work branch from develop,
    git checkout -b kernel

  4. did all my changes in "kernel" branch, pushed,created PR, now need to complete the PR. ie merge all kernel branch changes to develop but I do not want to see d3b229f9,16daa203,97e834cb commit messages, only want to see 5a555e7a from the below list. how can I get rid of 3 commit messages from both "develop" branch and "kernel" branch seamlessly?

Note: I did squash merge for kernel branch yet I could not get rid of commits I made in develop branch

"kernel" Branch has the below commits, I only want 5a555e7a message after the merge

5a555e7a (HEAD -> kernel, origin/kernel) new tool yaml file

d3b229f9 (develop) Merge branch 'develop' of github.com:softwarePlatform/Benchmark into develop

16daa203 Revert "kernel converter tool to create yaml file from lib logic"

97e834cb kernel converter tool to create yaml file from lib logic

f4af1648 (upstream/develop) Merge pull request #1244 from xxxxx/develop

b1a07da2 update version for new release

CodePudding user response:

You should not have reverted your commit on develop but just perform

git reset origin --hard

To fix all of this.

# update status
git fetch

# reset develop branch to match origin
git checkout develop
git reset origin --hard

# clean kernel history
git checkout kernel
git log
    commit 0080 (HEAD -> kernel, origin/kernel)
      Work 2

    commit 0070
      Work 1

    commit 0060
      Revert bad stuff

    commit 0050
      Bad stuff

    commit 0040 (develop, origin/develop)
      Good work before all this mess

# commit 0040 may not be (develop, origin/develop) if work have
# been done on this branch by someone else. It's not important but
# it makes it harder to find the last good commit.

# at this point keep a copy of the first and last sha of your work
# here 0070..0080
# then reset kernel to the last good commit
git reset --hard 0040

# apply your work
git cherry-pick 0070..0080

# update the PR
git push --force
  • Related