0

I have one git repository on github. The scenario is like this : In this repository, there is one folder called files. My collaborators very frequently make changes to this directory. I also have Dockerfile in this repo. I only want to build the docker image again if anything outside of files folder change. If not, I want to use the prebuilt docker image. This building and using docker images is done in Jenkins. Since directory files is changed very frequently, I don't want to build my docker image every time this directory changes.

How can I determine if in any commit, the changed files are in this directory or not?

Currently, I use a pygithub script, to make API calls to github, however, this is very slow, and also I have the repository already checked out. I wanted to know if I can achieve this using git commands. If so, this could be done very fast.

Ruchit Patel
  • 733
  • 1
  • 11
  • 26
  • I believe the answer you are looking for is [here](https://stackoverflow.com/questions/49853177/how-to-see-which-files-were-changed-in-last-commit). There they tell you how to get a list of changed files, from there you'll have to build your own parsing and testing script to fire the build or not. – Daemon Painter Feb 26 '21 at 09:42

1 Answers1

0

In your local clone:

git show --format= --name-only -- ':!files/'

git show --format= --name-only lists all changed files in the current commit (HEAD) compared to the previous commit (parent).

':!files/' excludes directory files from the list. See pathspec in git glossary.

If you want to list files changed between any commits use git diff --name-only. Example :

git diff --name-only HEAD~5 HEAD -- ':!files/'

for the last 5 commits.

phd
  • 82,685
  • 13
  • 120
  • 165