How to find out a list of all modified files in git for a complete jenkins build, and not for a specific commit?

How to find all modified files since the last build in GIT? I want to create not only the modified files in the main editor, but also all the modified files that were changed before this, as well as after the last successful build.

git show --pretty = "format:" - name-only will only build files with un-commit. Thus, I need to create for all modified files in different commits since the last successful build.

For example, the last build was done in Jenkins with X SHA-1 id, and after that there are 3 more fixes on it. So, my goal is to check the entire repository database to the head, and then find out a list of all the files that were changed after the X SHA-1 id, which are 3 commits on top of the last commit on the X SHA-1 id?

thanks

+11
source share
5 answers

A little late to the party, but a little better - use the --name-only functionality on git diff. I used the following:

 git diff --name-only $GIT_PREVIOUS_COMMIT $GIT_COMMIT 

Thus, after that you do not have to do some piping work.

+19
source

According to https://wiki.jenkins-ci.org/display/JENKINS/Git+Plugin#GitPlugin-Environmentvariables , Jenkins provides environment variables:

  • GIT_COMMIT - SHA of the current
  • GIT_PREVIOUS_COMMIT - SHA of the previous built-in commit from the same branch (current SHA at the first build in the branch)

I plan to use them to achieve something similar.

So what you need is something like:

 tar cvzf /tmp/build.tar.gz `git diff --stat $GIT_PREVIOUS_COMMIT $GIT_COMMIT | grep '\|' | awk '{print $1}'` 
+5
source

I'm not quite sure that I am following your question, but two things to consider:

  • git diff --stat {X SHA-1 ID} should work for what you are looking for. Or, you can be more explicit and make git diff --stat {X SHA-1 ID} {X SHA-1 ID + 3 commits} , which will give you change files between the two commits given. This will output something like:

     Library/ENV/4.3/cc | 3 ++- Library/Formula/cmu-sphinxbase.rb | 10 +++++++--- Library/Formula/fb-client.rb | 11 +++++++++++ 

    I leave this as a reading exercise to parse this output into a list of files.

  • You should probably make a complete, clean build in Jenkins, and not just create specific files. You may end up with unusual incompatibilities between embedded files. But this is beyond the scope of this question.

--- Edit with additional information ---

To break this problem apart:

  • Get SHA1 hashes to work with . You need the current HEAD repo (revision check, which we will call $CUR_HASH ) and commit, when the latter built Jenkins (Last Build Revision, which we will call $LAST_HASH ). It seems that you already have these, and if not, then this is beyond the scope of the question.
  • Get a list of files changed between $LAST_HASH and $CUR_HASH . This is the above git diff --stat $LAST_HASH $CUR_HASH , which will output something like the above.
  • Get only the filenames from the output - by doing this in bash, you can pass the output of git diff to grep '\|' to get only strings with file names, and then swipe it to awk '{print $1} to get only the file name, no statistics. So, the command now looks something like this:

     git diff --stat $LAST_HASH $CUR_HASH | grep '\|' | awk '{print $1}' 
  • Create tarball only from the modified files - you can send the output of the above to tar like this:

     tar cvzf /tmp/build.tar.gz `git diff --stat $LAST_HASH $CUR_HASH | grep '\|' | awk '{print $1}'` 

I think it covers everything that you are trying to do. Obviously, these commands cannot simply be copied / pasted, as I don’t know everything about your environment, but this is a good start.

+4
source

If you need it for Jenkins.

 prev_merge=$(git log |grep -C1 Merge | grep commit |head -n1 | awk {'print $2'}) commit=$(git log |head -n 1 | awk {'print $2'}) git diff --name-only $prev_merge $commit 
0
source

Maybe this is what you are looking for:

 git whatchanged origin/master -n 1 

This will tell you all the modified files since the last build.

To learn more about the git-whatchanged command: https://git-scm.com/docs/git-whatchanged/1.8.3

Also, if you only want to know the changes to the previous commit, change the command:

 git whatchanged -n 1 

Hope this helps.

0
source

Source: https://habr.com/ru/post/950754/


All Articles