簡體   English   中英

git cherry-pick 不是櫻桃采摘提交

[英]git cherry-pick isn't cherry-picking commits

原諒我糟糕的 git 但我有一個這樣的 git 日志:

commit fc9ab1fe1cfc2ac1e82e2de18a4244d94a7bb89f
Author: 
Date:   

    message 4

commit 3417248ab0953d715b3318f64635a825473bf73d
Author: 
Date:   

    message 3

commit da223a0b1e333a935b548a93f00263bb5b554cf7
Author: 
Date:   

    message 2

commit 1910a6cd9586e905258c6c9dcace2a7800a55f26
Author: 
Date:   

    message 1

我想保留最早的提交,做一個不同的提交來代替第二次提交,然后把第三次和第四次提交放在上面。 例如

舊:fc9ab1fe1cfc2ac1e82e2de18a4244d94a7bb89f 3417248ab0953d715b3318f64635a825473bf73d da223a0b1e333a935b548a93f00263bb5b554cf7 1910a6cd9586e905258c6c9dcace2a7800a55f26

新:fc9ab1fe1cfc2ac1e82e2de18a4244d94a7bb89f 3417248ab0953d715b3318f64635a825473bf73d replacement_commit 1910a6cd9586e9505c20dc60dc20953d715

這就是我如何成為“老”的

#changes
git add .
git commit -m "message1"
#changes
git add .
git commit -m "message2"
#changes
git add .
git commit -m "message3"
#changes
git add .
git commit -m "message4"
git push

這是我嘗試進行更改的方式

git pull
git reset 1910a6cd9586e905258c6c9dcace2a7800a55f26
git reset #removes all the later commits from staging
#make changes
git add .
git commit -m "replacement_commit"
#now to cherry pick the other two (which have already been pushed to a repository for this branch)
git cherry-pick 3417248ab0953d715b3318f64635a825473bf73d^..fc9ab1fe1cfc2ac1e82e2de18a4244d94a7bb89f

它不起作用。 輸出:

-> % git cherry-pick 3417248ab0953d715b3318f64635a825473bf73d^..fc9ab1fe1cfc2ac1e82e2de18a4244d94a7bb89f
On branch my_branch
Cherry-pick currently in progress.

nothing to commit, working tree clean
The previous cherry-pick is now empty, possibly due to conflict resolution.
If you wish to commit it anyway, use:

    git commit --allow-empty

and then use:

    git cherry-pick --continue

to resume cherry-picking the remaining commits.
If you wish to skip this commit, use:

    git cherry-pick --skip

有沒有辦法解決這個問題,或者有更好的方法可以做到這一點?

啊! 我在沒有“^”的情況下嘗試了它,並且奏效了!

git cherry-pick 3417248ab0953d715b3318f64635a825473bf73d..fc9ab1fe1cfc2ac1e82e2de18a4244d94a7bb89f

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM