Re: Is a given file known to git?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Christoph Duelli <duelli@xxxxxxxxxxxx> wrote:
> 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.
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux