0

GitLab run pipeline on git push. While running this pipeline I would like get list of files which are going to be pushed from all commits if there are multiple commits happend.

I am trying to get using this command

git diff-tree --no-commit-id --name-only -r ${CI_COMMIT_SHA} but this is giving only recent commit only. If there are more than one commit happend in the branch it is giving only last commit details. I would like to get all files which are committed during that push.

When git is able to find all the files from multiple commits which it needs to push , how can not we?

Techie
  • 759
  • 4
  • 11
  • 29

2 Answers2

1

This will solve my issue.

git whatchanged --name-only --pretty="" origin..HEAD

UPDATE: Above command also includes changes made to master through other branch. Let's say some one else pushed code changes to master and you did not pull them then when you run the above command, it shows those changes as diff in your current branch.

I think whatchanged is deprectated you can replace it with log

If you want to view changes only from your current branch , you can use this git diff master... --name-only or git diff --name-only master...<branch_name>

Techie
  • 759
  • 4
  • 11
  • 29
0

to view file changes between a given commit and your current commit use -

git diff --name-only <starting SHA> HEAD

and on being more general to your problem, to check which files changed between two commits do -

git diff --name-only <commit1> <commit2>.

samar taj Shaikh
  • 1,165
  • 11
  • 18
  • Thanks for your reply. In the above commands, How can I find ? I do not have any idea about the current branch. I am like a third person who wants to check files which are going to be pushed and run some script on those files. – Techie Aug 14 '18 at 04:58
  • means hash code of respective commit from which you want to view files. – samar taj Shaikh Aug 14 '18 at 05:54
  • His question is how to know what the last commit was since the last push. – Sam Mar 18 '21 at 10:35