git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: how to do these 2 one-liners ?

From
Junio C Hamano <junkio@cox.net>
Date
Mar 19, 2007, 22:44 UTC
Message-ID
<7vwt1cetuc.fsf@assigned-by-dhcp.cox.net>
In-Reply-To
<46d6db660703191525w613b02e1nae0f30efaca3b269@mail.gmail.com>
"Christian MICHON" <christian.michon@gmail.com> writes:
Show 6 quoted lines
> ================================================
> 1) how do I check the status of a single file ? ( the file is already
> added in the index)
>
> I usually use git-status here, but for single files that need update,
> there should be a faster way.

"git-diff-files $PATH" shows if it is different relative to the index, "git-diff-index HEAD $PATH" shows if it is different from the HEAD, and "git-diff-index --cached $PATH" shows if it is different between index and HEAD. git-status uses the first one and the third one AFAIR. You say "that need update", so probably you are interested in seeing the first one only without the third one.

If you have Git 1.5.1, then:
	if git diff-files --quiet $PATH
        then
        	echo Up to date
	else
        	echo Need update
	fi                
Another more portable way is:
	if test -z "$(git diff-files --raw $PATH)"
        then
        	echo Up to date
	else
        	echo Need update
	fi                
Show 6 quoted lines
> ================================================
> 2) how do I find in historical reverse order all the commits a
> certain file belongs to since the origin ?
>
> I usually do: git-log <file> | grep ^commit
> I would like to avoid piping here...
git-rev-list -m HEAD -- "$PATH"
Previous: Christian MICHONNext: Christian MICHON
Message 2 of 4 in “how to do these 2 one-liners ?”
  1. Christian MICHONMar 19, 2007
  2. Junio C HamanoMar 19, 2007
  3. Christian MICHONMar 19, 2007
  4. Linus TorvaldsMar 19, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.