0

Is it possible to get the script name and the path where that script is located, from git hash commit value

Suppose with the following details

script name - script.sh

path - /c/training/

I make some changes in script.sh and the commit hash is 123456789asdasdasdas (placeholder value)

Using the commit hash value, the output should be

script.sh /c/training/
Helium
  • 49
  • 7
  • 4
    A commit hash ID identifies one commit, uniquely. That one commit acts as an archive of some number of files. None of your question makes any sense to me, but given the hash ID and the repository holding that commit, you can ask Git to list out all the files contained inside that commit, using `git ls-tree -r`. – torek Aug 03 '21 at 13:50
  • 1
    Does this answer your question? [How do I list all of the files in a commit?](https://stackoverflow.com/questions/424071/how-do-i-list-all-of-the-files-in-a-commit) – TTT Aug 03 '21 at 14:22
  • @torek sorry the question wasn't clear, but for a unique commit hash, how do I get the list of files and the path where the files are stored as mentioned in the example above. – Helium Aug 11 '21 at 09:29
  • @TTT thank you it is close to what I am looking for but still trying out to get the path of the file as well. – Helium Aug 11 '21 at 09:30
  • @Nikhil both of the methods in the accepted answer display the full path in the results, relative to the repo root. – TTT Aug 11 '21 at 17:03
  • 1
    A commit just stores files. The files' names *are* path names: "path/to/file" is the file's name, as stored in a Git commit. There are no folders involved. Later, if you run `git checkout`, Git itself will construct the folder names `path` and `to` and will create the folder `to` inside the created folder `path` as needed. This `path/to` will live in the *working tree* as defined by the repository *at that time*. That is, if we run `mkdir /a/b/c && cd /a/b/c && git clone ` the *full* path will be `/a/b/c/path/to/file`. The `/a/b/c` part *is not stored in the repository*. – torek Aug 11 '21 at 18:15
  • 1
    Based on your reply to TTT I guess you're looking to have Git *automatically compare the set of files in the commit to the set of files in its parent commit*. That's what `git show` does, for instance. The result of this comparison, perhaps with options like `--name-only` or `--name-status` applied, will contain the *relative path name* in the repository: the `path/to/file` part. You *cannot get an absolute name* from this as the *front part* of the name is determined by *where you put your clone*. – torek Aug 11 '21 at 18:17

0 Answers0