Re: Is a given file known to git?
- From
Shawn O. Pearce <spearce@spearce.org>
- Date
- Mar 11, 2008, 07:24 UTC
- Message-ID
- <20080311072412.GP8410@spearce.org>
- In-Reply-To
- <47D6317D.7030700@melosgmbh.de>
Christoph Duelli <duelli@melosgmbh.de> wrote:
Show 8 quoted lines
> Given a repository and a path p to a file in it: > Is it possible (how?) to detect (in a bash script) if the file pointed > to by p is "known" to git? > Something along the line: > if `git knows p? > then > ... > fi
Depends on your definition of "known to git". You can look at the current index, which may have files newly added but not yet committed:
if test $(git ls-files "$p" | wc -l) -gt 0 then ... fi
you can look at a specific committed state too:
if git cat-file -e "$commit:$p" 2>/dev/null then ... fi
where $commit can be any tree-ish, so a tag, a branch, a commit, the symbolic-ref HEAD... etc.
-- Shawn.