I am trying to write a script that will use git to get the files that have changed and run commands based on that. I do my development with docker-compose and here is the repo I am working on https://github.com/my-grocery-price-book/www
when running git diff-files from inside the container it lists all the files.
when running git diff-files from outside the container list no files.
upgrading git inside the container to the latest version of 2.16 still gives the same output.
Steps to reproduce:
git clone https://github.com/my-grocery-price-book/www.git
docker-compose run --rm app bash
git diff-files
Anyone know what I need to do to get git to behave correctly inside docker?
git diff-files uses a hashing algorithm to compare files in the working tree and the index. The files in the working tree have the same hashes as the ones in a local environment.
My hypothesis is that when you run git diff-files in the docker container, the index wasn't reflected properly due to the docker volume mount and hence the output. This does not happen if you were to re-clone the entire repository in the docker container itself. However, if you switch context back to your local environment right after this and do git diff-files, the behavior is reversed (i.e. it lists all the files when you are outside the container, but not inside the container).
Here's what you can do since you might be switching between the docker container and your local environment:
git diff > /dev/null && git diff-files
Use git diff to refresh the index and force the output to /dev/null, then git diff-files will reflect the right output. You need to do this in both environments, especially when switching from one to another. If you feel that the whole command is too long, you might find git aliases to be helpful.
来源:https://stackoverflow.com/questions/49185186/fix-git-diff-files-listing-all-files-in-docker