Is there a way to preview changes made by cherry-picking multiple commits in Git before pushing them?

huangapple go评论53阅读模式
英文:

Is there a way to preview changes made by cherry-picking multiple commits in Git before pushing them?

问题

有没有办法查看从 cherry-pick 中的更改?我尝试了以下 cherry-pick 命令:

git cherry-pick commit-hash-1 commit-hash-2

对于多个提交,我遇到了多个冲突,我已经解决了这些冲突,但是无法在推送之前检查差异。

我可以在推送后查看更改并检查分支之间的差异,但我想在本地推送之前查看差异。

英文:

Is there any way to see the changes from the cherry-pick?, I was trying cherry-pick

git cherry-pick commit-hash-1 commit-hash-2

for multiple commits and i got multiple conflicts which i have resolved, but unable to check the difference before pushing it.

I can see the changes once i pushed and check difference between the branches, but i want to see the difference before pushing from the local.

答案1

得分: 1

要查看已提交但尚未推送到远程的本地分支中的更改,您可以使用(请注意origin是您的远程的名称):
git diff origin...

但更有趣的是查看已提交和未提交的更改(工作树),这样您可以检查您的工作,而无需提交,并修复您在代码中发现的任何问题。请注意,您只能查看已添加到git的文件的更改:
git diff-index -p --merge-base origin

要查看仅暂存文件的更改,您应该添加--cached
git diff-index -p --cached --merge-base origin

英文:

To see changes in your local branch that are committed but not pushed yet into remote you could use (note that origin is your remote's name):

git diff origin...

But more interesting is to see changes both committed and not (the working tree), that way you could check your work without even committing and fix any problems you find in the code. Note that you can see changes in files added to git only:

git diff-index -p --merge-base origin

To see changes in staged files only you should add --cached:

 git diff-index -p --cached --merge-base origin

huangapple
  • 本文由 发表于 2023年5月29日 18:52:13
  • 转载请务必保留本文链接:https://go.coder-hub.com/76356708.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定