* Re: rm and mv commands: should I use them?
2008-01-06 7:55 rm and mv commands: should I use them? Jon Hancock
@ 2008-01-06 8:04 ` David Brown
2008-01-06 8:08 ` Brian Swetland
` (3 subsequent siblings)
4 siblings, 0 replies; 11+ messages in thread
From: David Brown @ 2008-01-06 8:04 UTC (permalink / raw)
To: Jon Hancock; +Cc: git
On Sun, Jan 06, 2008 at 03:55:22PM +0800, Jon Hancock wrote:
> So, do I need to use git's mv and rm commands? Can't I just rename,
> add, and remove files using any means I like and then just ensure my
> "index" is staged properly when I do a commit?
Yes. You can use either git-rm or 'git-commit -a' to remove files. To
rename, you can use git-mv, or you can rename the file yourself, git-add
the new name, and git-rm the old name.
There is no metadata stored with git-mv and git-rm, they just update the
tree and the index.
Dave
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: rm and mv commands: should I use them?
2008-01-06 7:55 rm and mv commands: should I use them? Jon Hancock
2008-01-06 8:04 ` David Brown
@ 2008-01-06 8:08 ` Brian Swetland
2008-01-06 8:08 ` Jeff King
` (2 subsequent siblings)
4 siblings, 0 replies; 11+ messages in thread
From: Brian Swetland @ 2008-01-06 8:08 UTC (permalink / raw)
To: Jon Hancock; +Cc: git
[Jon Hancock <redstarling@gmail.com>]
>
> So, do I need to use git's mv and rm commands? Can't I just rename, add,
> and remove files using any means I like and then just ensure my "index" is
> staged properly when I do a commit? Additionally, is there a simple
> procedure with git to say: "I want to version exactly what is in my working
> tree. If I removed something or added something, just handle it". This is
> sort of what "git add ." does, but "git add" doesn't handling things I
> removed or moved, correct?
"git add ." only adds new or modified files to the index. You can use
"git add -u ." to update the index to reflect any deleted files.
Brian
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: rm and mv commands: should I use them?
2008-01-06 7:55 rm and mv commands: should I use them? Jon Hancock
2008-01-06 8:04 ` David Brown
2008-01-06 8:08 ` Brian Swetland
@ 2008-01-06 8:08 ` Jeff King
2008-01-06 19:22 ` Linus Torvalds
2008-01-07 3:05 ` Jay Soffian
4 siblings, 0 replies; 11+ messages in thread
From: Jeff King @ 2008-01-06 8:08 UTC (permalink / raw)
To: Jon Hancock; +Cc: git
On Sun, Jan 06, 2008 at 03:55:22PM +0800, Jon Hancock wrote:
> So, do I need to use git's mv and rm commands? Can't I just rename, add,
> and remove files using any means I like and then just ensure my "index" is
> staged properly when I do a commit?
No, you don't need to use those commands. They really are just wrappers
that manipulate the working tree files and the index at the same time.
So instead of "git-mv a b" you can do "mv a b; git rm a; git add b".
> Additionally, is there a simple procedure with git to say: "I want to
> version exactly what is in my working tree. If I removed something or
> added something, just handle it". This is sort of what "git add ."
> does, but "git add" doesn't handling things I removed or moved,
> correct?
"git add ." will add the contents of any modified files to the index, as
well as add any untracked files (which may or may not be what you want).
It will not add removals. Try "git add -u" which updates all files that
git knows about (i.e., modifications and removals). You can also simply
use "git commit -a" which is the moral equivalent of "git add -u ; git
commit".
-Peff
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: rm and mv commands: should I use them?
2008-01-06 7:55 rm and mv commands: should I use them? Jon Hancock
` (2 preceding siblings ...)
2008-01-06 8:08 ` Jeff King
@ 2008-01-06 19:22 ` Linus Torvalds
2008-01-07 1:55 ` Jeff King
2008-01-07 3:05 ` Jay Soffian
4 siblings, 1 reply; 11+ messages in thread
From: Linus Torvalds @ 2008-01-06 19:22 UTC (permalink / raw)
To: Jon Hancock; +Cc: git
On Sun, 6 Jan 2008, Jon Hancock wrote:
>
> So, do I need to use git's mv and rm commands?
Nope.
They are there only to
(a) make people who are used to do "svn mv" not complain
(b) simplify things a little teeny bit, by avoiding having to "git add"
the new file.
So if you do just a rename, you can do either
git mv old-file new-file
git commit
or you can do
mv old-file new-file
git add new-file
git commit -a
and the *result* will be the same (the "git commit -a" is there to
automatically pick up the fact that "old-file" went away: you could have
done it with "git rm old-file" too, or "git add -u" or any number of
other ways that update the index).
> Can't I just rename, add, and remove files using any means I like and
> then just ensure my "index" is staged properly when I do a commit?
Absolutely. And depending on your workflow, that may well be the right
thing to do.
In particular, this all means that it's perfectly fine to make changes to
a git repository using *any* non-git-aware tools, including things like
graphical file managers etc.
> Additionally, is there a simple procedure with git to say: "I want to
> version exactly what is in my working tree. If I removed something or
> added something, just handle it". This is sort of what "git add ."
> does, but "git add" doesn't handling things I removed or moved, correct?
You should be able to do that with either
git add .
git commit -a
or if you don't want to do a commit, you can do a
git add -u
git add .
where the "git add -u" will look at any files git already knows and update
them (which includes removing them if they are gone), and then "git add ."
will add any new files.
Linus
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: rm and mv commands: should I use them?
2008-01-06 19:22 ` Linus Torvalds
@ 2008-01-07 1:55 ` Jeff King
2008-01-07 2:05 ` Junio C Hamano
0 siblings, 1 reply; 11+ messages in thread
From: Jeff King @ 2008-01-07 1:55 UTC (permalink / raw)
To: Linus Torvalds; +Cc: Jon Hancock, git
On Sun, Jan 06, 2008 at 11:22:50AM -0800, Linus Torvalds wrote:
> > So, do I need to use git's mv and rm commands?
>
> Nope.
>
> They are there only to
>
> (a) make people who are used to do "svn mv" not complain
>
> (b) simplify things a little teeny bit, by avoiding having to "git add"
> the new file.
I haven't looked to see if this optimization is in place, but "git mv"
can also avoid having to recompute the sha1 of the file (which in most
cases doesn't matter, but on a large file with a cold cache, can make
the operation seem just as snappy as a regular "mv").
-Peff
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: rm and mv commands: should I use them?
2008-01-07 1:55 ` Jeff King
@ 2008-01-07 2:05 ` Junio C Hamano
2008-01-07 3:06 ` Jeff King
0 siblings, 1 reply; 11+ messages in thread
From: Junio C Hamano @ 2008-01-07 2:05 UTC (permalink / raw)
To: Jeff King; +Cc: Linus Torvalds, Jon Hancock, git
Jeff King <peff@peff.net> writes:
> I haven't looked to see if this optimization is in place, but "git mv"
> can also avoid having to recompute the sha1 of the file (which in most
> cases doesn't matter, but on a large file with a cold cache, can make
> the operation seem just as snappy as a regular "mv").
Actually, I think I found a bug.
$ git reset --hard
$ echo >>Makefile
$ git diff --numstat
1 0 Makefile
$ git mv Makefile makefile
$ git diff
$ git diff --cached -M --numstat
1 0 Makefile => makefile
"git mv" should not have staged the change. It should have
moved the index entry from Makefile to makefile and moved the
work tree files.
The fix for this would fall out from your "optimization" quite
naturally, but I think that might be a post 1.5.4 item.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: rm and mv commands: should I use them?
2008-01-07 2:05 ` Junio C Hamano
@ 2008-01-07 3:06 ` Jeff King
2008-01-07 18:37 ` Robin Rosenberg
0 siblings, 1 reply; 11+ messages in thread
From: Jeff King @ 2008-01-07 3:06 UTC (permalink / raw)
To: Junio C Hamano; +Cc: Linus Torvalds, Jon Hancock, git
On Sun, Jan 06, 2008 at 06:05:16PM -0800, Junio C Hamano wrote:
> Actually, I think I found a bug.
>
> $ git reset --hard
> $ echo >>Makefile
> $ git diff --numstat
> 1 0 Makefile
> $ git mv Makefile makefile
> $ git diff
> $ git diff --cached -M --numstat
> 1 0 Makefile => makefile
>
> "git mv" should not have staged the change. It should have
> moved the index entry from Makefile to makefile and moved the
> work tree files.
I thought there was some discussion about this a few months ago,
concerning what exactly it should do, and that was how we arrived at the
current behavior. However, I can't seem to find it now. Maybe I dreamed
it.
-Peff
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: rm and mv commands: should I use them?
2008-01-07 3:06 ` Jeff King
@ 2008-01-07 18:37 ` Robin Rosenberg
0 siblings, 0 replies; 11+ messages in thread
From: Robin Rosenberg @ 2008-01-07 18:37 UTC (permalink / raw)
To: Jeff King; +Cc: Junio C Hamano, Linus Torvalds, Jon Hancock, git
måndagen den 7 januari 2008 skrev Jeff King:
> On Sun, Jan 06, 2008 at 06:05:16PM -0800, Junio C Hamano wrote:
...
> > "git mv" should not have staged the change. It should have
> > moved the index entry from Makefile to makefile and moved the
> > work tree files.
>
> I thought there was some discussion about this a few months ago,
> concerning what exactly it should do, and that was how we arrived at the
> current behavior. However, I can't seem to find it now. Maybe I dreamed
> it.
I had the same dream.
-- robin
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: rm and mv commands: should I use them?
2008-01-06 7:55 rm and mv commands: should I use them? Jon Hancock
` (3 preceding siblings ...)
2008-01-06 19:22 ` Linus Torvalds
@ 2008-01-07 3:05 ` Jay Soffian
2008-01-07 5:01 ` David Brown
4 siblings, 1 reply; 11+ messages in thread
From: Jay Soffian @ 2008-01-07 3:05 UTC (permalink / raw)
To: Jon Hancock; +Cc: git
On 1/6/08, Jon Hancock <redstarling@gmail.com> wrote:
> Additionally, is there
> a simple procedure with git to say: "I want to version exactly what is
> in my working tree. If I removed something or added something, just
> handle it".
>From http://www-cs-students.stanford.edu/~blynn/gitmagic/ch05.html#id2553633
is the helpful hint:
$ git-ls-files -d -m -o -z | xargs -0 git-update-index --add --remove
I've got the following aliases in my .gitconfig:
alias.addremove=!git-ls-files -d -m -o -z -X .git/info/exclude -X
$(git-config core.excludesfile) --exclude-per-directory=.gitignore |
xargs -0 git-update-index --add --remove
alias.ls=!git-ls-files -d -m -o -v -X .git/info/exclude -X
$(git-config core.excludesfile) --exclude-per-directory=.gitignore
(In 1.5.4, you can replace the two -X's and the
--exclude-per-directory with --exclude-standard.)
j.
^ permalink raw reply [flat|nested] 11+ messages in thread