查找提交之间发生更改的目录

时间:2017-05-30 08:30:18

标签: git jenkins subdirectory git-diff

我正在设置一个jenkins作业,它遍历项目中的目录,并在每个目录中执行类似的操作。

虽然,现在,由于我有少量目录,所以重复所有目录并不是什么大问题。但是我只想迭代在GIT_PREVIOUS_COMMITGIT_COMMIT之间进行了更改的目录。

我现在的工作是什么:

for dir in */
do
  cd $dir
  # test a script exists
  # execute the script
  # upload the result.zip to an S3 bucket
  cd ..
done

2 个答案:

答案 0 :(得分:3)

您可以将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以删除文件名。然后排序& uniq获取您感兴趣的目录的唯一列表:

sed 's,/*[^/]\+/*$,,' | sort | uniq 

app/controllers
app/models
app/views/some

答案 1 :(得分:0)

您可以为此类活动添加自己的别名。它非常方便!

在.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 $1 $2; }; f"

然后你可以将它们用作:

 git dbc ab68a12 fc83334 # for diff between two commits.

git dbh # for diff between previous and current HEAD.