有没有办法将当前项目与 git 分支进行比较并创建差异补丁

Is there a way to compare current project with a git branch and create a patch of the differences

在 IntelliJ 中,我可以右键单击文件夹或项目的根目录,然后在 Git 上下文菜单下执行“与分支比较...”。我想获得以下结果差异到 patch/diff 文件。我如何从 IntelliJ 或命令行 git?

完成此操作

您搜索的 diff 选项是 -p (doc).

git diff -p reference-branch target-branch > yourfile.patch

似乎是任何时候实现此目标的最简单方法。


但是,如果您只为命令提供一个提交引用,您也可以使用当前分支被假定为引用这一事实。

因此,您的 reference-branch 目前已签出 :

git diff -p target-branch > yourfile.patch