admin管理员组

文章数量:1026989

Let's say I have a branch with 5 commits in main:

The older: A Then: B, C, D And the latest: E

I need to rollback to the hash "B", but also, I need the changes of the commit "D" and "E".

I can't do this:

git checkout main
git pull origin main
git checkout B
git cherry-pick D
git cherry-pick E

Doing that git will return fatal: bad object because D and E are not in the log.

How can I rollback to a certain hash, but also pick 2 newer commits?

Let's say I have a branch with 5 commits in main:

The older: A Then: B, C, D And the latest: E

I need to rollback to the hash "B", but also, I need the changes of the commit "D" and "E".

I can't do this:

git checkout main
git pull origin main
git checkout B
git cherry-pick D
git cherry-pick E

Doing that git will return fatal: bad object because D and E are not in the log.

How can I rollback to a certain hash, but also pick 2 newer commits?

Share Improve this question asked Dec 11, 2024 at 20:43 pmirandapmiranda 8,41017 gold badges90 silver badges180 bronze badges 7
  • 2 The shown command sequence is nothing out of the ordinary and should work, provided you used reasonable values for the commit IDs. Show the history and commit graph: git log --graph --oneline main and the exact commands, including commit IDs, and the exact error message. – j6t Commented Dec 11, 2024 at 21:48
  • 1 It's not about the commits being newer that is causing the problem. skipping commits is something that is ok (it can easily be done using an interactive rebase). Can we see in the question the output of git log --graph --oneline --all and the commands you are running and their outputs? – eftshift0 Commented Dec 11, 2024 at 21:49
  • 2 It's like @j6t and I are clones :-D – eftshift0 Commented Dec 11, 2024 at 21:50
  • I have realized that I had to use (in my case) the "squash commits". There's a bot that after each merged PR deletes the original branch, and add it's own commit, with a different hash. Using those on the cherry worked fine. Thanks for the comments. – pmiranda Commented Dec 12, 2024 at 12:40
  • @eftshift0 And I'm your bare clone, guys ;'-) – Romain Valeri Commented Dec 12, 2024 at 14:10
 |  Show 2 more comments

1 Answer 1

Reset to default 0

I have realized that I had to use (in my case) the "squash commits". There's a bot that after each merged PR deletes the original branch, and add it's own commit, with a different hash. Using those on the cherry worked fine. Thanks for the comments.

Let's say I have a branch with 5 commits in main:

The older: A Then: B, C, D And the latest: E

I need to rollback to the hash "B", but also, I need the changes of the commit "D" and "E".

I can't do this:

git checkout main
git pull origin main
git checkout B
git cherry-pick D
git cherry-pick E

Doing that git will return fatal: bad object because D and E are not in the log.

How can I rollback to a certain hash, but also pick 2 newer commits?

Let's say I have a branch with 5 commits in main:

The older: A Then: B, C, D And the latest: E

I need to rollback to the hash "B", but also, I need the changes of the commit "D" and "E".

I can't do this:

git checkout main
git pull origin main
git checkout B
git cherry-pick D
git cherry-pick E

Doing that git will return fatal: bad object because D and E are not in the log.

How can I rollback to a certain hash, but also pick 2 newer commits?

Share Improve this question asked Dec 11, 2024 at 20:43 pmirandapmiranda 8,41017 gold badges90 silver badges180 bronze badges 7
  • 2 The shown command sequence is nothing out of the ordinary and should work, provided you used reasonable values for the commit IDs. Show the history and commit graph: git log --graph --oneline main and the exact commands, including commit IDs, and the exact error message. – j6t Commented Dec 11, 2024 at 21:48
  • 1 It's not about the commits being newer that is causing the problem. skipping commits is something that is ok (it can easily be done using an interactive rebase). Can we see in the question the output of git log --graph --oneline --all and the commands you are running and their outputs? – eftshift0 Commented Dec 11, 2024 at 21:49
  • 2 It's like @j6t and I are clones :-D – eftshift0 Commented Dec 11, 2024 at 21:50
  • I have realized that I had to use (in my case) the "squash commits". There's a bot that after each merged PR deletes the original branch, and add it's own commit, with a different hash. Using those on the cherry worked fine. Thanks for the comments. – pmiranda Commented Dec 12, 2024 at 12:40
  • @eftshift0 And I'm your bare clone, guys ;'-) – Romain Valeri Commented Dec 12, 2024 at 14:10
 |  Show 2 more comments

1 Answer 1

Reset to default 0

I have realized that I had to use (in my case) the "squash commits". There's a bot that after each merged PR deletes the original branch, and add it's own commit, with a different hash. Using those on the cherry worked fine. Thanks for the comments.

本文标签: Gitcreate a branch from old commit and add some new commitsStack Overflow