* how to do these 2 one-liners ?
@ 2007-03-19 22:25 Christian MICHON
2007-03-19 22:44 ` Junio C Hamano
2007-03-19 23:09 ` Linus Torvalds
0 siblings, 2 replies; 4+ messages in thread
From: Christian MICHON @ 2007-03-19 22:25 UTC (permalink / raw)
To: git
Hi list,
in order to code a gvim plugin for git (I started something), I now miss
2 one-liners, and I hope experts around this list will find it easy
to answer (for the sake of this plugin)
================================================
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.
================================================
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...
I may need more than these 2 one-liners, if they're doable.
I'll post something soon :)
Thanks in advance!
--
Christian
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: how to do these 2 one-liners ?
2007-03-19 22:25 how to do these 2 one-liners ? Christian MICHON
@ 2007-03-19 22:44 ` Junio C Hamano
2007-03-19 22:59 ` Christian MICHON
2007-03-19 23:09 ` Linus Torvalds
1 sibling, 1 reply; 4+ messages in thread
From: Junio C Hamano @ 2007-03-19 22:44 UTC (permalink / raw)
To: Christian MICHON; +Cc: git
"Christian MICHON" <christian.michon@gmail.com> writes:
> ================================================
> 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
> ================================================
> 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"
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: how to do these 2 one-liners ?
2007-03-19 22:44 ` Junio C Hamano
@ 2007-03-19 22:59 ` Christian MICHON
0 siblings, 0 replies; 4+ messages in thread
From: Christian MICHON @ 2007-03-19 22:59 UTC (permalink / raw)
To: git
On 3/19/07, Junio C Hamano <junkio@cox.net> send 2 nice
one-liners...
Thanks Junio :)
I'll use these 2 tomorrow. I wasn't that far in my last experiments
for the 2nd one...
--
Christian
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: how to do these 2 one-liners ?
2007-03-19 22:25 how to do these 2 one-liners ? Christian MICHON
2007-03-19 22:44 ` Junio C Hamano
@ 2007-03-19 23:09 ` Linus Torvalds
1 sibling, 0 replies; 4+ messages in thread
From: Linus Torvalds @ 2007-03-19 23:09 UTC (permalink / raw)
To: Christian MICHON; +Cc: git
On Mon, 19 Mar 2007, Christian MICHON wrote:
>
> in order to code a gvim plugin for git (I started something), I now miss
> 2 one-liners, and I hope experts around this list will find it easy
> to answer (for the sake of this plugin)
>
> ================================================
> 1) how do I check the status of a single file ? ( the file is already
> added in the index)
It really depends on what you want to do.
If you want to know *what* the index contains right there and then, do for
example:
git ls-files --stage -- "$filename"
and it will tell you the index contents (it might be several lines: if the
"filename" entry is a directory it will list *all* files under that
directory, but even if it's a single file it could give you all the
unmerged stages for that file).
On the other hand, often you want to know what the status of a file is not
in "absolute" terms, but relative to the index or to the last commit. If
so, you can use something like
git diff-files --name-status -- "$filename"
which just compares the index with the current working tree. And if you
want to check against the last commit (ie HEAD), use
git diff-index --name-status HEAD -- "$filename"
which can also be used with "--cached" to see the difference between the
HEAD and the index. That's how "git status" used to do it when it was a
shell script (now it's done with a built-in).
In fact, you could look at the old git-commit.sh script before it was
turned into a built-in with
git show v1.4.0:git-commit.sh
and look at the "run_status" shell function.
> I usually use git-status here, but for single files that need update,
> there should be a faster way.
Indeed. HOWEVER! Note that when you ask for the status of a single file,
that obviously means that there is no "rename detection" going on, so if
you want to see the "renamed from Xyz", you need to do the global analysis
that "git-status" does, and then fetch the filename info from there.
(Alternatively, you can choose to always do the single-file case first,
and then only *if* it's a newly added file you could ask "was it renamed
from anything else").
> 2) how do I find in historical reverse order all the commits a
> certain file belongs to since the origin ?
That's quite an expensive operation:
git rev-list --reverse HEAD -- "$filename"
Or did you by "historical" mean "newest first"? If so, just do
git rev-list HEAD -- "$filename"
(that's the order that git considers "natural").
> I usually do: git-log <file> | grep ^commit
> I would like to avoid piping here...
Well, "git log" is really just rev-list with fancy options to make it show
more than just the commit name.
Of course, you *could* do
git log --pretty=oneline -- "$filename"
which gets you pretty close. But if you literally just want the commit
SHA1, "git rev-list" is what you're really asking for.
Linus
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2007-03-19 23:10 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-03-19 22:25 how to do these 2 one-liners ? Christian MICHON
2007-03-19 22:44 ` Junio C Hamano
2007-03-19 22:59 ` Christian MICHON
2007-03-19 23:09 ` Linus Torvalds
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.