Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

compare git commit to extracted directory

Tags:

git

I have a git directory and another separate directory where I extracted all the files, but not the .git directory

my question is:

how do I compare a specific commit of the git directory to the files in the extracted directory?

edit:

  1. I know the commit hash,
  2. I cant do a git checkout because I want to leave the git directory intact
  3. I have a large git tree and I need to do the diff fast as possible
  4. The git directory is not necessarily checkout to the specific commit.
like image 655
yigal Avatar asked Jun 19 '26 05:06

yigal


1 Answers

You can temporarily (for the duration of the git diff command itself only) override Git's notion of where the work-tree lives:

git --work-tree=<path-to-tree> diff <commit>

Or, equivalently, from that path:

git --git-dir=<path-to-.git-directory> diff <commit>

(which uses . as the work-tree path while obtaining commits from the given .git directory).

Use whichever is most convenient. This might even be to use both options. Specifically, with --git-dir=path, Git will assume that the current working directory is the top level of the work-tree unless you also specify --work-tree=top-of-work-tree. One or both paths may be relative to the current working directory.

(This all works with git diff-tree, git diff-index, and git diff-files as well, though it's probably most useful with git diff-tree for scripts and git diff for personal usage.)

like image 148
torek Avatar answered Jun 21 '26 21:06

torek



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!