有没有办法在实际执行 'git cherry-pick' 命令之前显示将要应用的更改?我想看到一个类似于 'git diff' 的更改列表,而不会真正地进行更改或修改任何内容。
git cherry-pick
没有像其他命令一样提供 --dry-run
选项。
但是,虽然不完全符合你的要求,你可以通过利用 -n
(--no-commit
) 选项 进行测试。
回滚操作将非常简单 :
(假设您从一个干净的工作树开始)
# cherry-pick without actually committing
git cherry-pick -n <commit>
# inspect changes
git diff --staged
# wipe all these temporary changes to go back to where you started
git reset --hard
git reset --hard
命令之后,git status
返回了 Cherry-pick currently in progress. (run "git cherry-pick --continue" to continue) ...
。运行 --continue
命令将一切恢复到 git cherry-pick -n <commit>
之前的状态。 - Abdull2.39.1
中),根本不需要执行git reset --hard
;git cherry-pick --abort
将会恢复到git cherry-pick -n <commit>
执行之前的状态。 - Abdull我已在一个(临时)分支上做了这样的“实验”。原始主分支未被更改。
git checkout -b cherry-test
git cherry-pick <sha1>
git show/log/whatever
git checkout master
git branch -D cherry-test
我相信你可以通过以下方式在分支上的最后一次提交和你想要挑选的提交之间进行 git diff:
git diff [last-commit-hash] [cherry-pick-commit-hash]
git show
命令会显示与git cherry-pick
将尝试应用到您当前提交的相同差异。因此,如果您在考虑“我可能喜欢提交a123456
,让我看看它做了什么”,那么您将运行git show a123456
来查看它做了什么。然后,您可以决定是否尝试进行 cherry-pick。 - torek