{"thread":{"id":"11490","subject":"rm and mv commands: should I use them?","startedAt":"2008-01-06T07:55:22Z","lastAt":"2008-01-07T18:37:38Z","messageCount":11,"participants":["Jon Hancock","David Brown","Jeff King","Brian Swetland","Linus Torvalds","Junio C Hamano","Jay Soffian","Robin Rosenberg"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"64573","messageId":"379EDA94-A67B-483A-BC5F-E961DD52AD0C@gmail.com","threadId":"11490","inReplyTo":null,"subject":"rm and mv commands: should I use them?","fromName":"Jon Hancock","fromEmail":"redstarling@gmail.com","sentAt":"2008-01-06T07:55:22Z","receivedAt":"2008-01-06T07:55:22Z","isPatch":false,"sender":{"key":"redstarling@gmail.com","avatar":null},"body":"Hello list,\nI'm fairly new to git and coming from svn and have tasted hg and bzr  \nalong the decision path.\n\nHere's my newbie issue:\n\nIn reading Aristotle Pagaltzis's article http://plasmasturm.org/log/ \n487/  the author stresses that a major difference between git and  \nsomething like bzr or svn is that git tracks content and not metadata  \n(or at least less metadata); meaning is inferred through content and  \nless through metadata.\n\nThe heart of Pagaltzis's argument copied here:\n<COPY>\nAmong the systems I did look into, there are really just two  \ncontenders: git and Mercurial. All the other systems track metadata;  \ngit and hg just track content and infer the metadata.\n\nBy tracking metadata I mean that these systems keep a record of what  \nsteps were taken. “This file had its name changed.” “Those  \nmodifications came from that file in that branch.” “This file was  \ncopied from that file.” Tracking content alone means doing none of  \nthat. When you commit, the VCS just records what the tree looks like.  \nIt doesn’t care about how the tree got that way. When you ask it about  \ntwo revisions, it looks at the tree beforehand and the tree  \nafterwards, and figures out what happened inbetween. A file is not a  \nunit that defines any sort of boundary in this view. The VCS always  \nlooks at entire trees; files have no individual identity separate from  \ntheir trees at all.\n\nAs a consequence, whether you used VCS tools to manipulate your  \nworking copy or regular command line utilities or applied a patch or  \nwhatever is irrelevant. The resulting history is always the same.\n</COPY>\n\nSo, do I need to use git's mv and rm commands?  Can't I just rename,  \nadd, and remove files using any means I like and then just ensure my  \n\"index\" is staged properly when I do a commit?  Additionally, is there  \na simple procedure with git to say: \"I want to version exactly what is  \nin my working tree.  If I removed something or added something, just  \nhandle it\".  This is sort of what \"git add .\" does, but \"git add\"  \ndoesn't handling things I removed or moved, correct?\n\nthanks, Jon\n"},{"id":"64574","messageId":"20080106080415.GA15268@old.davidb.org","threadId":"11490","inReplyTo":"379EDA94-A67B-483A-BC5F-E961DD52AD0C@gmail.com","subject":"Re: rm and mv commands: should I use them?","fromName":"David Brown","fromEmail":"git@davidb.org","sentAt":"2008-01-06T08:04:15Z","receivedAt":"2008-01-06T08:04:15Z","isPatch":false,"sender":{"key":"git@davidb.org","avatar":"https://gravatar.com/avatar/94c86a2938470a74c2eac5e2b69afc0871f79a660295c02219597aba8cb101c1?d=mp&s=160"},"body":"On Sun, Jan 06, 2008 at 03:55:22PM +0800, Jon Hancock wrote:\n\n> So, do I need to use git's mv and rm commands?  Can't I just rename,  \n> add, and remove files using any means I like and then just ensure my  \n> \"index\" is staged properly when I do a commit?\n\nYes.  You can use either git-rm or 'git-commit -a' to remove files.  To\nrename, you can use git-mv, or you can rename the file yourself, git-add\nthe new name, and git-rm the old name.\n\nThere is no metadata stored with git-mv and git-rm, they just update the\ntree and the index.\n\nDave\n"},{"id":"64577","messageId":"20080106080801.GA1483@bulgaria.corp.google.com","threadId":"11490","inReplyTo":"379EDA94-A67B-483A-BC5F-E961DD52AD0C@gmail.com","subject":"Re: rm and mv commands: should I use them?","fromName":"Brian Swetland","fromEmail":"swetland@google.com","sentAt":"2008-01-06T08:08:01Z","receivedAt":"2008-01-06T08:08:01Z","isPatch":false,"sender":{"key":"swetland@google.com","avatar":"https://gravatar.com/avatar/b26b7c772097c55d8febb0fc027dd2ef577a05994a321819f49ab3c9153ac8b1?d=mp&s=160"},"body":"[Jon Hancock <redstarling@gmail.com>]\n>\n> So, do I need to use git's mv and rm commands?  Can't I just rename, add, \n> and remove files using any means I like and then just ensure my \"index\" is \n> staged properly when I do a commit?  Additionally, is there a simple \n> procedure with git to say: \"I want to version exactly what is in my working \n> tree.  If I removed something or added something, just handle it\".  This is \n> sort of what \"git add .\" does, but \"git add\" doesn't handling things I \n> removed or moved, correct?\n\n\"git add .\" only adds new or modified files to the index.  You can use\n\"git add -u .\" to update the index to reflect any deleted files.\n\nBrian\n"},{"id":"64576","messageId":"20080106080825.GA9718@coredump.intra.peff.net","threadId":"11490","inReplyTo":"379EDA94-A67B-483A-BC5F-E961DD52AD0C@gmail.com","subject":"Re: rm and mv commands: should I use them?","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2008-01-06T08:08:25Z","receivedAt":"2008-01-06T08:08:25Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Sun, Jan 06, 2008 at 03:55:22PM +0800, Jon Hancock wrote:\n\n> So, do I need to use git's mv and rm commands?  Can't I just rename, add, \n> and remove files using any means I like and then just ensure my \"index\" is \n> staged properly when I do a commit?\n\nNo, you don't need to use those commands. They really are just wrappers\nthat manipulate the working tree files and the index at the same time.\nSo instead of \"git-mv a b\" you can do \"mv a b; git rm a; git add b\".\n\n> Additionally, is there a simple procedure with git to say: \"I want to\n> version exactly what is in my working tree.  If I removed something or\n> added something, just handle it\".  This is sort of what \"git add .\"\n> does, but \"git add\" doesn't handling things I removed or moved,\n> correct?\n\n\"git add .\" will add the contents of any modified files to the index, as\nwell as add any untracked files (which may or may not be what you want).\nIt will not add removals. Try \"git add -u\" which updates all files that\ngit knows about (i.e., modifications and removals). You can also simply\nuse \"git commit -a\" which is the moral equivalent of \"git add -u ; git\ncommit\".\n\n-Peff\n"},{"id":"64600","messageId":"alpine.LFD.1.00.0801061108320.2811@woody.linux-foundation.org","threadId":"11490","inReplyTo":"379EDA94-A67B-483A-BC5F-E961DD52AD0C@gmail.com","subject":"Re: rm and mv commands: should I use them?","fromName":"Linus Torvalds","fromEmail":"torvalds@linux-foundation.org","sentAt":"2008-01-06T19:22:50Z","receivedAt":"2008-01-06T19:22:50Z","isPatch":false,"sender":{"key":"torvalds@linux-foundation.org","avatar":"https://avatars.githubusercontent.com/u/1024025?v=4"},"body":"\n\nOn Sun, 6 Jan 2008, Jon Hancock wrote:\n> \n> So, do I need to use git's mv and rm commands?\n\nNope.\n\nThey are there only to\n\n (a) make people who are used to do \"svn mv\" not complain\n\n (b) simplify things a little teeny bit, by avoiding having to \"git add\" \n     the new file.\n\nSo if you do just a rename, you can do either\n\n\tgit mv old-file new-file\n\tgit commit\n\nor you can do\n\n\tmv old-file new-file\n\tgit add new-file\n\tgit commit -a\n\nand the *result* will be the same (the \"git commit -a\" is there to \nautomatically pick up the fact that \"old-file\" went away: you could have \ndone it with \"git rm old-file\" too, or \"git add -u\" or any number of \nother ways that update the index).\n\n> Can't I just rename, add, and remove files using any means I like and \n> then just ensure my \"index\" is staged properly when I do a commit?\n\nAbsolutely. And depending on your workflow, that may well be the right \nthing to do. \n\nIn particular, this all means that it's perfectly fine to make changes to \na git repository using *any* non-git-aware tools, including things like \ngraphical file managers etc.\n\n\n> Additionally, is there a simple procedure with git to say: \"I want to \n> version exactly what is in my working tree.  If I removed something or \n> added something, just handle it\".  This is sort of what \"git add .\" \n> does, but \"git add\" doesn't handling things I removed or moved, correct?\n\nYou should be able to do that with either\n\n\tgit add .\n\tgit commit -a\n\nor if you don't want to do a commit, you can do a\n\n\tgit add -u\n\tgit add .\n\nwhere the \"git add -u\" will look at any files git already knows and update \nthem (which includes removing them if they are gone), and then \"git add .\" \nwill add any new files.\n\n\t\tLinus\n"},{"id":"64612","messageId":"20080107015518.GD17748@coredump.intra.peff.net","threadId":"11490","inReplyTo":"alpine.LFD.1.00.0801061108320.2811@woody.linux-foundation.org","subject":"Re: rm and mv commands: should I use them?","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2008-01-07T01:55:19Z","receivedAt":"2008-01-07T01:55:19Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Sun, Jan 06, 2008 at 11:22:50AM -0800, Linus Torvalds wrote:\n\n> > So, do I need to use git's mv and rm commands?\n> \n> Nope.\n> \n> They are there only to\n> \n>  (a) make people who are used to do \"svn mv\" not complain\n> \n>  (b) simplify things a little teeny bit, by avoiding having to \"git add\" \n>      the new file.\n\nI haven't looked to see if this optimization is in place, but \"git mv\"\ncan also avoid having to recompute the sha1 of the file (which in most\ncases doesn't matter, but on a large file with a cold cache, can make\nthe operation seem just as snappy as a regular \"mv\").\n\n-Peff\n"},{"id":"64614","messageId":"7v63y62xwj.fsf@gitster.siamese.dyndns.org","threadId":"11490","inReplyTo":"20080107015518.GD17748@coredump.intra.peff.net","subject":"Re: rm and mv commands: should I use them?","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2008-01-07T02:05:16Z","receivedAt":"2008-01-07T02:05:16Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jeff King <peff@peff.net> writes:\n\n> I haven't looked to see if this optimization is in place, but \"git mv\"\n> can also avoid having to recompute the sha1 of the file (which in most\n> cases doesn't matter, but on a large file with a cold cache, can make\n> the operation seem just as snappy as a regular \"mv\").\n\nActually, I think I found a bug.\n\n\t$ git reset --hard\n\t$ echo >>Makefile\n        $ git diff --numstat\n        1\t0\tMakefile\n        $ git mv Makefile makefile\n        $ git diff\n        $ git diff --cached -M --numstat\n        1\t0\tMakefile => makefile\n\n\"git mv\" should not have staged the change.  It should have\nmoved the index entry from Makefile to makefile and moved the\nwork tree files.\n\nThe fix for this would fall out from your \"optimization\" quite\nnaturally, but I think that might be a post 1.5.4 item.\n"},{"id":"64616","messageId":"76718490801061905k30c1ac86r51a65165d47807d4@mail.gmail.com","threadId":"11490","inReplyTo":"379EDA94-A67B-483A-BC5F-E961DD52AD0C@gmail.com","subject":"Re: rm and mv commands: should I use them?","fromName":"Jay Soffian","fromEmail":"jaysoffian@gmail.com","sentAt":"2008-01-07T03:05:34Z","receivedAt":"2008-01-07T03:05:34Z","isPatch":false,"sender":{"key":"jaysoffian@gmail.com","avatar":"https://avatars.githubusercontent.com/u/155970?v=4"},"body":"On 1/6/08, Jon Hancock <redstarling@gmail.com> wrote:\n> Additionally, is there\n> a simple procedure with git to say: \"I want to version exactly what is\n> in my working tree.  If I removed something or added something, just\n> handle it\".\n\n>From http://www-cs-students.stanford.edu/~blynn/gitmagic/ch05.html#id2553633\nis the helpful hint:\n\n$ git-ls-files -d -m -o -z | xargs -0 git-update-index --add --remove\n\nI've got the following aliases in my .gitconfig:\n\nalias.addremove=!git-ls-files -d -m -o -z -X .git/info/exclude -X\n$(git-config core.excludesfile) --exclude-per-directory=.gitignore |\nxargs -0 git-update-index --add --remove\n\nalias.ls=!git-ls-files -d -m -o -v -X .git/info/exclude -X\n$(git-config core.excludesfile) --exclude-per-directory=.gitignore\n\n(In 1.5.4, you can replace the two -X's and the\n--exclude-per-directory with --exclude-standard.)\n\nj.\n"},{"id":"64617","messageId":"20080107030642.GA18194@coredump.intra.peff.net","threadId":"11490","inReplyTo":"7v63y62xwj.fsf@gitster.siamese.dyndns.org","subject":"Re: rm and mv commands: should I use them?","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2008-01-07T03:06:42Z","receivedAt":"2008-01-07T03:06:42Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Sun, Jan 06, 2008 at 06:05:16PM -0800, Junio C Hamano wrote:\n\n> Actually, I think I found a bug.\n> \n> \t$ git reset --hard\n> \t$ echo >>Makefile\n>         $ git diff --numstat\n>         1\t0\tMakefile\n>         $ git mv Makefile makefile\n>         $ git diff\n>         $ git diff --cached -M --numstat\n>         1\t0\tMakefile => makefile\n> \n> \"git mv\" should not have staged the change.  It should have\n> moved the index entry from Makefile to makefile and moved the\n> work tree files.\n\nI thought there was some discussion about this a few months ago,\nconcerning what exactly it should do, and that was how we arrived at the\ncurrent behavior. However, I can't seem to find it now. Maybe I dreamed\nit.\n\n-Peff\n"},{"id":"64620","messageId":"20080107050128.GA20484@old.davidb.org","threadId":"11490","inReplyTo":"76718490801061905k30c1ac86r51a65165d47807d4@mail.gmail.com","subject":"Re: rm and mv commands: should I use them?","fromName":"David Brown","fromEmail":"git@davidb.org","sentAt":"2008-01-07T05:01:28Z","receivedAt":"2008-01-07T05:01:28Z","isPatch":false,"sender":{"key":"git@davidb.org","avatar":"https://gravatar.com/avatar/94c86a2938470a74c2eac5e2b69afc0871f79a660295c02219597aba8cb101c1?d=mp&s=160"},"body":"On Sun, Jan 06, 2008 at 10:05:34PM -0500, Jay Soffian wrote:\n>On 1/6/08, Jon Hancock <redstarling@gmail.com> wrote:\n>> Additionally, is there\n>> a simple procedure with git to say: \"I want to version exactly what is\n>> in my working tree.  If I removed something or added something, just\n>> handle it\".\n>\n>>From http://www-cs-students.stanford.edu/~blynn/gitmagic/ch05.html#id2553633\n>is the helpful hint:\n>\n>$ git-ls-files -d -m -o -z | xargs -0 git-update-index --add --remove\n\nAs long as your git is new enough to have git-add -u, you should be able to\ndo:\n\n   $ git add .\n   $ git add -u\n\nand have the index match the working tree (keeping excludes out).\n\nDave\n"},{"id":"64658","messageId":"200801071937.38976.robin.rosenberg.lists@dewire.com","threadId":"11490","inReplyTo":"20080107030642.GA18194@coredump.intra.peff.net","subject":"Re: rm and mv commands: should I use them?","fromName":"Robin Rosenberg","fromEmail":"robin.rosenberg.lists@dewire.com","sentAt":"2008-01-07T18:37:38Z","receivedAt":"2008-01-07T18:37:38Z","isPatch":false,"sender":{"key":"robin.rosenberg@dewire.com","avatar":"https://avatars.githubusercontent.com/u/46357?v=4"},"body":"måndagen den 7 januari 2008 skrev Jeff King:\n> On Sun, Jan 06, 2008 at 06:05:16PM -0800, Junio C Hamano wrote:\n...\n> > \"git mv\" should not have staged the change.  It should have\n> > moved the index entry from Makefile to makefile and moved the\n> > work tree files.\n> \n> I thought there was some discussion about this a few months ago,\n> concerning what exactly it should do, and that was how we arrived at the\n> current behavior. However, I can't seem to find it now. Maybe I dreamed\n> it.\n\nI had the same dream.\n\n-- robin\n"}]}