docker


🏷️ Use git diff in a Docker container

Within a Docker container, if we are located in a git repository and try to execute git diff, there will be no problems. However, if the current working directory is not a git repository and we try to execute git diff /full/path/to/git/repo, the command will fail, complaining about not a working repository. This is something relevant to the environment and configuration within the Docker container. To solve this issue, we can set up the GIT_DIR environment variable first, change to the git repository directory, and then execute git diff [1],

export GIT_DIR=/full/path/to/git/repo/.git
cd /full/path/to/git/repo
git diff


References

[1] Solution provided by GPT3.5 Turbo model.