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 | Show 2 more comments1 Answer
Reset to default 0I 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
1 Answer
Reset to default 0I 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
版权声明:本文标题:git, create a branch from old commit and add some new commits - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1736028849a1380840.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
git log --graph --oneline main
and the exact commands, including commit IDs, and the exact error message. – j6t Commented Dec 11, 2024 at 21:48git log --graph --oneline --all
and the commands you are running and their outputs? – eftshift0 Commented Dec 11, 2024 at 21:49