查找在提交之间发生更改的目录
Find directories that had changes between commits
我正在设置一个 jenkins 作业,它遍历项目中的目录,并在每个目录中执行类似的操作。
而现在,由于我的目录数量很少,因此遍历所有目录并不是什么大问题。但我只想遍历在 GIT_PREVIOUS_COMMIT
和 GIT_COMMIT
.
之间进行更改的目录
我现在的工作是做什么的:
for dir in */
do
cd $dir
# test a script exists
# execute the script
# upload the result.zip to an S3 bucket
cd ..
done
您可以使用 git diff 和 --name-only
选项。这将列出更改的文件:
$ git diff --name-only GIT_COMMIT..GIT_PREVIOUS_COMMIT
app/controllers/some_controller.rb
app/models/some_model.rb
app/views/some/show.html.erb
app/views/some/index.html.erb
然后,您可以将其通过管道传递给 sed 以删除文件名。然后 sort & uniq 得到一个唯一的你感兴趣的目录列表:
sed 's,/*[^/]\+/*$,,' | sort | uniq
app/controllers
app/models
app/views/some
您可以为此类活动添加自己的别名。它非常方便!
将这些添加到您的 .gitconfig 中:
38 # Difference between HEAD and HEAD^
39 dbh = "!git ls --numstat -1"
40 # Difference between two commits
41 dbc = "!f() { git diff --name-status ; }; f"
然后您可以将它们用作:
git dbc ab68a12 fc83334 # for diff between two commits.
或
git dbh # for diff between previous and current HEAD.
我正在设置一个 jenkins 作业,它遍历项目中的目录,并在每个目录中执行类似的操作。
而现在,由于我的目录数量很少,因此遍历所有目录并不是什么大问题。但我只想遍历在 GIT_PREVIOUS_COMMIT
和 GIT_COMMIT
.
我现在的工作是做什么的:
for dir in */
do
cd $dir
# test a script exists
# execute the script
# upload the result.zip to an S3 bucket
cd ..
done
您可以使用 git diff 和 --name-only
选项。这将列出更改的文件:
$ git diff --name-only GIT_COMMIT..GIT_PREVIOUS_COMMIT
app/controllers/some_controller.rb
app/models/some_model.rb
app/views/some/show.html.erb
app/views/some/index.html.erb
然后,您可以将其通过管道传递给 sed 以删除文件名。然后 sort & uniq 得到一个唯一的你感兴趣的目录列表:
sed 's,/*[^/]\+/*$,,' | sort | uniq
app/controllers
app/models
app/views/some
您可以为此类活动添加自己的别名。它非常方便!
将这些添加到您的 .gitconfig 中:
38 # Difference between HEAD and HEAD^
39 dbh = "!git ls --numstat -1"
40 # Difference between two commits
41 dbc = "!f() { git diff --name-status ; }; f"
然后您可以将它们用作:
git dbc ab68a12 fc83334 # for diff between two commits.
或
git dbh # for diff between previous and current HEAD.