[英]Git diff is not showing absolute differences between files on different branches (raw differences across all commits)
[英]Git save raw files between commits
我想保存/导出两个选定提交之间不同的文件。 以下命令显示修改过的文件...
$ git diff-tree --no-commit-id --name-only -r bd61ad98
index.html
javascript/application.js
javascript/ie6.js
但是有一种导出它们的方法,可以保留文件结构吗? 我只需要将修改后的文件保存在Web服务器中,而不是上传整个项目。
参见git archive 。
git diff-tree --no-commit-id --name-only -r $commit \
| xargs git archive -o changedfiles.tgz --
应该这样做。
这只是一个小的Shell脚本的种子(将其保存在文件中并使该文件可执行)。 它不是一个完整的脚本。 您需要检查命令行中是否提供了$1
否则中止并显示一条错误消息(否则该脚本的其余部分将因误导性错误消息而失败)。 无论它位于何处以及从何处调用,它都必须起作用(仅当当前目录为项目目录时,它才可以起作用)。 它需要以某种方式处理已删除的文件(它们是git diff-tree
命令返回的吗?)
#!/bin/bash
commit=$1 # get the commit hash from the command line (the first argument)
dest='/tmp' # path to your destination directory (change it to match your setup)
# Cleanup on the destination directory
rm -rf $dest
mkdir $dest
# Copy the modified files
for i in $(git diff-tree --no-commit-id --name-only -r $commit); do
cp --parents $i $dest/
done
采用
git diff-tree --no-commit-id --name-only -r bd61ad98 | git archive --format zip --output "proj-diff.zip" master -0
-0 arg用于未压缩的存档; 我还没有测试过,但这应该工作
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.