[GIT] git diff 实用命令

目录

  • 1. git diff 制作patch补丁包
    • 1.1 将文件打包进patch包
    • 1.2 将新文件打包进patch包
    • 1.3 将二进制文件打包进patch包

1. git diff 制作patch补丁包

1.1 将文件打包进patch包

$ git diff        //查看尚未暂存的文件更新了哪些内容
$ git diff > test.patch     //将差异打到patch里,新文件不会打到patch里面

1.2 将新文件打包进patch包

$ git diff --cached     //查看已经暂存起来的文件和上次提交的版本之间的差异
$ git diff --cached > test.patch     //将差异打到patch里,新文件会打到patch里面,二进制文件不会打到patch里面

注意:diff一些不支持差异比较的文件会打不进patch里面,比如bmp图片文件,需要增加 --binary选项

1.3 将二进制文件打包进patch包

$ git diff --binary test.bmp > test.patch
$ patch -p1 < test.patch           //直接使用patch指令应用包含二进制文件的patch包会失败
File test.bmp: git binary diffs are not supported.
$ git apply test.patch           //使用git apply指令应用包含二进制文件的patch包

你可能感兴趣的:(git,linux,git)