{"thread":{"id":"17412","subject":"(beginner) git rm","startedAt":"2009-01-28T10:11:38Z","lastAt":"2009-01-29T02:34:32Z","messageCount":16,"participants":["Zabre","Peter Krefting","Tomas Carnecky","Theodore Tso","Björn Steinbrink","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"102294","messageId":"1233137498146-2231416.post@n2.nabble.com","threadId":"17412","inReplyTo":null,"subject":"(beginner) git rm","fromName":"Zabre","fromEmail":"427@free.fr","sentAt":"2009-01-28T10:11:38Z","receivedAt":"2009-01-28T10:11:38Z","isPatch":false,"sender":{"key":"427@free.fr","avatar":null},"body":"\nHi,\n\nI am learning git and there is something I don't get : why a file deleted in\na branch gets also deleted in my master?\n(For the moment I'm only working locally, no remote repository)\n\nI have a master branch containing 4 text files called a.txt , b.txt , c.txt\n, d.txt . (in HEAD)\n\nI create a new branch from there (masters HEAD) and go to this new branch.\n$ git branch new\n$ git checkout new\n\nI delete one file in the new branch\n$ git rm d.txt\n$ ls\na.txt b.txt c.txt\n\nThen I go back to the master branch and list the files there\n$ git checkout master\n$ls\na.txt b.txt c.txt\n\nI have not modified the master branch, why is d.txt deleted there also?\n\nThere must be something I did not understand in git behaviour (something to\ndo with the index?)\nThank you for your help.\n-- \nView this message in context: http://n2.nabble.com/%28beginner%29-git-rm-tp2231416p2231416.html\nSent from the git mailing list archive at Nabble.com.\n"},{"id":"102296","messageId":"Pine.LNX.4.64.0901281133380.645@ds9.cixit.se","threadId":"17412","inReplyTo":"1233137498146-2231416.post@n2.nabble.com","subject":"Re: (beginner) git rm","fromName":"Peter Krefting","fromEmail":"peter@softwolves.pp.se","sentAt":"2009-01-28T10:36:40Z","receivedAt":"2009-01-28T10:36:40Z","isPatch":false,"sender":{"key":"peter@softwolves.pp.se","avatar":"https://avatars.githubusercontent.com/u/990764?v=4"},"body":"Zabre:\n\n> I delete one file in the new branch\n> $ git rm d.txt\n> $ ls\n> a.txt b.txt c.txt\n\nHere you have not yet committed the change, so the change is only in\nthe staging area. You need to\n\n  git commit\n\nto create a commit on your branch.\n\n> Then I go back to the master branch and list the files there\n> $ git checkout master\n\nSince you have not yet made any commits to your branch, master and new\nboth point to the same commit, meaning that this is does nothing but\nchanges which branch you are committing to.\n\n> $ls\n> a.txt b.txt c.txt\n\nYou are in the same place as you were a moment ago, but you have told\nGit that you want to commit the removal to master instead of new.\n\n-- \n\\\\// Peter - http://www.softwolves.pp.se/\n"},{"id":"102300","messageId":"1233140751523-2231622.post@n2.nabble.com","threadId":"17412","inReplyTo":"Pine.LNX.4.64.0901281133380.645@ds9.cixit.se","subject":"Re: (beginner) git rm","fromName":"Zabre","fromEmail":"427@free.fr","sentAt":"2009-01-28T11:05:51Z","receivedAt":"2009-01-28T11:05:51Z","isPatch":false,"sender":{"key":"427@free.fr","avatar":null},"body":"\n\nPeter Krefting wrote:\n> \n> Here you have not yet committed the change, so the change is only in\n> the staging area. You need to\n> \n>   git commit\n> \n> to create a commit on your branch.\n> \n\nThank you Peter.\nI've just done a hard reset and redid it the right way. It worked as\nexpected.\n\n$ git checkout new\n$ rm d.txt\n$ git rm d.txt\n$ git commit\n\nI am a little bit confused regarding rm : first I did a simple \"rm\" but git\nwould not commit, so I had to \"git rm\" for the index to be modified and have\nsomething to commit. Is this the right way to do things?\n\nAnother question would be : instead of doing a hard reset (I might have\nother changes in the index that I don't want to loose) is it possible to\nremove only one \"delete action\" from the index?\n-- \nView this message in context: http://n2.nabble.com/%28beginner%29-git-rm-tp2231416p2231622.html\nSent from the git mailing list archive at Nabble.com.\n"},{"id":"102301","messageId":"49804385.908@dbservice.com","threadId":"17412","inReplyTo":"1233140751523-2231622.post@n2.nabble.com","subject":"Re: (beginner) git rm","fromName":"Tomas Carnecky","fromEmail":"tom@dbservice.com","sentAt":"2009-01-28T11:37:41Z","receivedAt":"2009-01-28T11:37:41Z","isPatch":false,"sender":{"key":"tom@dbservice.com","avatar":"https://gravatar.com/avatar/900a300bdd1a8bbe086008ad78210bbee2ad2803b7d50a5cba04c1e9404bd6d2?d=mp&s=160"},"body":"On 01/28/2009 12:05 PM, Zabre wrote:\n> Another question would be : instead of doing a hard reset (I might have\n> other changes in the index that I don't want to loose) is it possible to\n> remove only one \"delete action\" from the index?\n\nDo you mean 'undelete' a file? git checkout d.txt - That restores the \nfile in the working tree and resets the index just for that file.\n\ntom\n"},{"id":"102302","messageId":"1233144045221-2231849.post@n2.nabble.com","threadId":"17412","inReplyTo":"49804385.908@dbservice.com","subject":"Re: (beginner) git rm","fromName":"Zabre","fromEmail":"427@free.fr","sentAt":"2009-01-28T12:00:45Z","receivedAt":"2009-01-28T12:00:45Z","isPatch":false,"sender":{"key":"427@free.fr","avatar":null},"body":"\n\nTomas Carnecky wrote:\n> \n> Do you mean 'undelete' a file? git checkout d.txt - That restores the \n> file in the working tree and resets the index just for that file.\n> \n\nHi Tom,\n(thank you for your interest in my newbie problems)\n\nyes that's what I mean : 'undelete' a file, after a \"git rm d.txt\".\nBut I did not manage to apply your solution succesfully :\n$ git rm d.txt\n$ ls\na.txt b.txt c.txt\n$ git status\n# On branch new\n# Changes to be committed:\n#   (use \"git reset HEAD <file>...\" to unstage)\n#\n#\tdeleted:    d.txt\n#\n$ git checkout d.txt\nerror: pathspec 'mamma.txt' did not match any file(s) known to git.\nDid you forget to 'git add'?\n\nSo it did not work but I've just noticed that unstage tip given by the\nstatus command, and I did the following (which worked)\n\n$ git reset HEAD d.txt\nd.txt: needs update\n$ ls\na.txt b.txt c.txt\n$ git checkout d.txt\n$ ls\na.txt b.txt c.txt d.txt\n\nReading the git reset help file gives me the feeling I should use this with\ncaution... It looks like you can somehow modify the change history.\nAnyway these two commands helped me change the index the way I wanted.\nPlease tell me if this might somehow go wrong in another situation.\n-- \nView this message in context: http://n2.nabble.com/%28beginner%29-git-rm-tp2231416p2231849.html\nSent from the git mailing list archive at Nabble.com.\n"},{"id":"102303","messageId":"49804D41.3010801@dbservice.com","threadId":"17412","inReplyTo":"1233144045221-2231849.post@n2.nabble.com","subject":"Re: (beginner) git rm","fromName":"Tomas Carnecky","fromEmail":"tom@dbservice.com","sentAt":"2009-01-28T12:19:13Z","receivedAt":"2009-01-28T12:19:13Z","isPatch":false,"sender":{"key":"tom@dbservice.com","avatar":"https://gravatar.com/avatar/900a300bdd1a8bbe086008ad78210bbee2ad2803b7d50a5cba04c1e9404bd6d2?d=mp&s=160"},"body":"On 01/28/2009 01:00 PM, Zabre wrote:\n>\n> Tomas Carnecky wrote:\n>> Do you mean 'undelete' a file? git checkout d.txt - That restores the\n>> file in the working tree and resets the index just for that file.\n>>\n>\n> Hi Tom,\n> (thank you for your interest in my newbie problems)\n>\n> yes that's what I mean : 'undelete' a file, after a \"git rm d.txt\".\n> But I did not manage to apply your solution succesfully :\n> $ git rm d.txt\n> $ ls\n> a.txt b.txt c.txt\n> $ git status\n> # On branch new\n> # Changes to be committed:\n> #   (use \"git reset HEAD<file>...\" to unstage)\n> #\n> #\tdeleted:    d.txt\n> #\n> $ git checkout d.txt\n> error: pathspec 'mamma.txt' did not match any file(s) known to git.\n> Did you forget to 'git add'?\n\nOops, sorry. git checkout HEAD -- d.txt\nYou have to tell which version of d.txt you want. In your case the \nversion in HEAD.\n\ntom\n"},{"id":"102306","messageId":"20090128130333.GA11160@mit.edu","threadId":"17412","inReplyTo":"49804D41.3010801@dbservice.com","subject":"Re: (beginner) git rm","fromName":"Theodore Tso","fromEmail":"tytso@mit.edu","sentAt":"2009-01-28T13:03:33Z","receivedAt":"2009-01-28T13:03:33Z","isPatch":false,"sender":{"key":"tytso@mit.edu","avatar":"https://avatars.githubusercontent.com/u/51416?v=4"},"body":"On Wed, Jan 28, 2009 at 01:19:13PM +0100, Tomas Carnecky wrote:\n>\n> Oops, sorry. git checkout HEAD -- d.txt\n> You have to tell which version of d.txt you want. In your case the  \n> version in HEAD.\n>\n\nI use this command enough that I have this defined as an alias in my\n~/.gitconfig file.  Try running this command:\n\n\tgit config --global alias.revert-file \"checkout HEAD --\"\n\nNow you will be able to do this:\n\n\tgit revert-file d.txt\n\nThis is also useful when I've edited d.txt, and decided that I didn't\ngo about it the right away, and so I want to revert my edits.\n\n\t\t\t\t\t\t- Ted\n"},{"id":"102332","messageId":"1233166992184-2233892.post@n2.nabble.com","threadId":"17412","inReplyTo":"49804D41.3010801@dbservice.com","subject":"Re: (beginner) git rm","fromName":"Zabre","fromEmail":"427@free.fr","sentAt":"2009-01-28T18:23:12Z","receivedAt":"2009-01-28T18:23:12Z","isPatch":false,"sender":{"key":"427@free.fr","avatar":null},"body":"\n\nTomas Carnecky wrote:\n> \n> Oops, sorry. git checkout HEAD -- d.txt\n> You have to tell which version of d.txt you want. In your case the \n> version in HEAD.\n> \n\nThank you for this precision, it makes me understand this command better.\n(Sorry for my late answer I've been unable to check my computer for a few\nhours)\n-- \nView this message in context: http://n2.nabble.com/%28beginner%29-git-rm-tp2231416p2233892.html\nSent from the git mailing list archive at Nabble.com.\n"},{"id":"102333","messageId":"1233167117028-2233899.post@n2.nabble.com","threadId":"17412","inReplyTo":"20090128130333.GA11160@mit.edu","subject":"Re: (beginner) git rm","fromName":"Zabre","fromEmail":"427@free.fr","sentAt":"2009-01-28T18:25:17Z","receivedAt":"2009-01-28T18:25:17Z","isPatch":false,"sender":{"key":"427@free.fr","avatar":null},"body":"\n\nTheodore Tso wrote:\n> \n> I use this command enough that I have this defined as an alias in my\n> ~/.gitconfig file.  Try running this command:\n> \n> \tgit config --global alias.revert-file \"checkout HEAD --\"\n> \n> Now you will be able to do this:\n> \n> \tgit revert-file d.txt\n> \n> This is also useful when I've edited d.txt, and decided that I didn't\n> go about it the right away, and so I want to revert my edits.\n> \n\nVery good, I'll try that. (Plus it shows me how to customize git, thanks!)\n(Sorry for my late answer I've been unable to check my computer for a few\nhours)\n-- \nView this message in context: http://n2.nabble.com/%28beginner%29-git-rm-tp2231416p2233899.html\nSent from the git mailing list archive at Nabble.com.\n"},{"id":"102341","messageId":"20090128201727.GD7503@atjola.homenet","threadId":"17412","inReplyTo":"1233166992184-2233892.post@n2.nabble.com","subject":"Re: (beginner) git rm","fromName":"Björn Steinbrink","fromEmail":"b.steinbrink@gmx.de","sentAt":"2009-01-28T20:17:27Z","receivedAt":"2009-01-28T20:17:27Z","isPatch":false,"sender":{"key":"b.steinbrink@gmx.de","avatar":"https://avatars.githubusercontent.com/u/230962?v=4"},"body":"On 2009.01.28 10:23:12 -0800, Zabre wrote:\n> Tomas Carnecky wrote:\n> > \n> > Oops, sorry. git checkout HEAD -- d.txt\n> > You have to tell which version of d.txt you want. In your case the \n> > version in HEAD.\n> \n> Thank you for this precision, it makes me understand this command better.\n> (Sorry for my late answer I've been unable to check my computer for a few\n> hours)\n\nThe \"git checkout -- d.txt\" is also a valid command, but that restores\nthe file from the index.\n\ngit checkout -- paths\n\t==> Copy \"paths\" from the index to the working tree\n\ngit checkout <tree-ish> -- paths\n\t==> Copy \"paths\" from the tree-ish to the index and working tree\n\nSo, for \"rm d.txt\", a plain \"git checkout -- d.txt\" would also do the\ntrick, as d.txt is still in the index. But your \"git rm d.txt\" also\nremoved the file from the index, and thus that checkout does nothing.\nBut \"git checkout HEAD -- d.txt\" works, as it gets the file from HEAD\nand puts it into the index and working tree.\n\nBjörn\n"},{"id":"102346","messageId":"1233175322729-2234796.post@n2.nabble.com","threadId":"17412","inReplyTo":"20090128201727.GD7503@atjola.homenet","subject":"Re: (beginner) git rm","fromName":"Zabre","fromEmail":"427@free.fr","sentAt":"2009-01-28T20:42:02Z","receivedAt":"2009-01-28T20:42:02Z","isPatch":false,"sender":{"key":"427@free.fr","avatar":null},"body":"\n\nBjörn Steinbrink wrote:\n> \n> The \"git checkout -- d.txt\" is also a valid command, but that restores\n> the file from the index.\n> \n> git checkout -- paths\n> \t==> Copy \"paths\" from the index to the working tree\n> \n> git checkout <tree-ish> -- paths\n> \t==> Copy \"paths\" from the tree-ish to the index and working tree\n> \n> So, for \"rm d.txt\", a plain \"git checkout -- d.txt\" would also do the\n> trick, as d.txt is still in the index. But your \"git rm d.txt\" also\n> removed the file from the index, and thus that checkout does nothing.\n> But \"git checkout HEAD -- d.txt\" works, as it gets the file from HEAD\n> and puts it into the index and working tree.\n> \n\nThis is enlightening, thank you very much!\n(I knew I would love git more and more)\n\nOh just one (probably stupid) thing : <tree-ish> does represent a directory\nbeing the root of a tree of folders (which has been added to the index),\ndoes it?\nThis is the way I understand it at the moment. It must be a convention I\ndon't know just yet. (I need to investigate on this)\n-- \nView this message in context: http://n2.nabble.com/%28beginner%29-git-rm-tp2231416p2234796.html\nSent from the git mailing list archive at Nabble.com.\n"},{"id":"102349","messageId":"1233176743011-2234918.post@n2.nabble.com","threadId":"17412","inReplyTo":"1233175322729-2234796.post@n2.nabble.com","subject":"Re: (beginner) git rm","fromName":"Zabre","fromEmail":"427@free.fr","sentAt":"2009-01-28T21:05:43Z","receivedAt":"2009-01-28T21:05:43Z","isPatch":false,"sender":{"key":"427@free.fr","avatar":null},"body":"\n\nZabre wrote:\n> \n> Oh just one (probably stupid) thing : <tree-ish> does represent a\n> directory being the root of a tree of folders (which has been added to the\n> index), does it?\n> This is the way I understand it at the moment. It must be a convention I\n> don't know just yet. (I need to investigate on this)\n> \n\nOk I found in the doc (in the \"The Object Database\" section) what trees are\nabout, seems a little bit more obscure, so I guess I'm not ready for this\nright now. (I'm a beginner trying to use git for a simple regular workflow,\nmanaging code and other documents)\nhttp://www.kernel.org/pub/software/scm/git/docs/user-manual.html#the-object-database\nI guess <tree-ish> refers to such an object, and you use it in order to\nrevert it from the Object Database.\nI'll keep this idea in mind for when I'll try to restore data from tricky\nlast-chance \"stores\", there is a section about such things in the doc :\nhttp://www.kernel.org/pub/software/scm/git/docs/user-manual.html#fixing-mistakes\nI think that in a normal everyday use, the small index modification I can do\nusing the previous advices can do the job (or am I wrong?)\n-- \nView this message in context: http://n2.nabble.com/%28beginner%29-git-rm-tp2231416p2234918.html\nSent from the git mailing list archive at Nabble.com.\n"},{"id":"102351","messageId":"7vab9bm85b.fsf@gitster.siamese.dyndns.org","threadId":"17412","inReplyTo":"1233175322729-2234796.post@n2.nabble.com","subject":"Re: (beginner) git rm","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-01-28T21:29:36Z","receivedAt":"2009-01-28T21:29:36Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Zabre <427@free.fr> writes:\n\n> Björn Steinbrink wrote:\n>> \n>> The \"git checkout -- d.txt\" is also a valid command, but that restores\n>> the file from the index.\n>> \n>> git checkout -- paths\n>> \t==> Copy \"paths\" from the index to the working tree\n>> \n>> git checkout <tree-ish> -- paths\n>> \t==> Copy \"paths\" from the tree-ish to the index and working tree\n>> \n>> So, for \"rm d.txt\", a plain \"git checkout -- d.txt\" would also do the\n>> trick, as d.txt is still in the index. But your \"git rm d.txt\" also\n>> removed the file from the index, and thus that checkout does nothing.\n>> But \"git checkout HEAD -- d.txt\" works, as it gets the file from HEAD\n>> and puts it into the index and working tree.\n>\n> This is enlightening, thank you very much!\n> (I knew I would love git more and more)\n>\n> Oh just one (probably stupid) thing : <tree-ish> does represent a directory\n> being the root of a tree of folders (which has been added to the index),\n> does it?\n\nYeah, it typically is a commit object.\n\nBjörn said \"Copy\", but the operation really is like checking out a book\nfrom a library and \"checkout\" is a good word for it.  \"I do not like what\nI have in my work tree, and I'd like to replace it with a fresh one taken\nout of the index (or, out of that commit)\".\n"},{"id":"102360","messageId":"20090128221355.GE7503@atjola.homenet","threadId":"17412","inReplyTo":"7vab9bm85b.fsf@gitster.siamese.dyndns.org","subject":"Re: (beginner) git rm","fromName":"Björn Steinbrink","fromEmail":"b.steinbrink@gmx.de","sentAt":"2009-01-28T22:13:55Z","receivedAt":"2009-01-28T22:13:55Z","isPatch":false,"sender":{"key":"b.steinbrink@gmx.de","avatar":"https://avatars.githubusercontent.com/u/230962?v=4"},"body":"[Zabre, please keep the Cc: list when replying]\n\nOn 2009.01.28 13:29:36 -0800, Junio C Hamano wrote:\n> Zabre <427@free.fr> writes:\n> > Björn Steinbrink wrote:\n> >> \n> >> The \"git checkout -- d.txt\" is also a valid command, but that restores\n> >> the file from the index.\n> >> \n> >> git checkout -- paths\n> >> \t==> Copy \"paths\" from the index to the working tree\n> >> \n> >> git checkout <tree-ish> -- paths\n> >> \t==> Copy \"paths\" from the tree-ish to the index and working tree\n> >> \n> >> So, for \"rm d.txt\", a plain \"git checkout -- d.txt\" would also do the\n> >> trick, as d.txt is still in the index. But your \"git rm d.txt\" also\n> >> removed the file from the index, and thus that checkout does nothing.\n> >> But \"git checkout HEAD -- d.txt\" works, as it gets the file from HEAD\n> >> and puts it into the index and working tree.\n> >\n> > This is enlightening, thank you very much!\n> > (I knew I would love git more and more)\n> >\n> > Oh just one (probably stupid) thing : <tree-ish> does represent a directory\n> > being the root of a tree of folders (which has been added to the index),\n> > does it?\n> \n> Yeah, it typically is a commit object.\n> \n> Björn said \"Copy\", but the operation really is like checking out a book\n> from a library and \"checkout\" is a good word for it.  \"I do not like what\n> I have in my work tree, and I'd like to replace it with a fresh one taken\n> out of the index (or, out of that commit)\".\n\nWith \"checkout\", I'm still a bit unsure about which term to use, because\nof the behaviour you get with, for example, \"git checkout HEAD --\ndirectory\". It always just adds or replaces files, but never removes\nthem. So it's not really like taking the old directory out of the repo\nand using that instead. For example:\n\ngit rm dir/old_file\necho 123 > dir/new_file\ngit add dir/new_file\ngit checkout HEAD -- dir\n\nThat won't remove dir/new_file from the index (and of course it won't\ndrop it from the working tree). That's the one thing where \"git checkout\nHEAD -- dir\" differs from \"git reset HEAD -- dir && git checkout --\ndir\". IIRC we've talked about that on #git a few months ago, but I don't\nrecall what conclusions we came up with.\n\nIt would probably be better to say that checkout only works with the\nblobs (because the index doesn't have entries for trees, right?) that\nexist in the given tree-ish. And thus it doesn't remove entries from the\nindex. But that feels a bit convoluted. :-/\n\nBjörn\n"},{"id":"102364","messageId":"7v7i4fkqmo.fsf@gitster.siamese.dyndns.org","threadId":"17412","inReplyTo":"20090128221355.GE7503@atjola.homenet","subject":"Re: (beginner) git rm","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-01-28T22:33:19Z","receivedAt":"2009-01-28T22:33:19Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Björn Steinbrink <B.Steinbrink@gmx.de> writes:\n\n> With \"checkout\", I'm still a bit unsure about which term to use, because\n> of the behaviour you get with, for example, \"git checkout HEAD --\n> directory\".\n> ...\n> It would probably be better to say that checkout only works with the\n> blobs (because the index doesn't have entries for trees, right?).\n\nTrue, it is not just \"checkout\".  There is no such thing as \"directory\" in\ngit UI, in that sense.\n\nWhen you say:\n\n\tgit checkout [<tree-ish>] -- pathspec\n\nyou may be using the same string as the name of an existing directory, but\nthat does not change the fact that you are giving a pathspec pattern to\nspecify the set of paths in the index (or in the <tree-ish>) that matches\nthe pathspec.\n"},{"id":"102391","messageId":"20090129023432.GF7503@atjola.homenet","threadId":"17412","inReplyTo":"6bef44ba0901281711m2d05e70fj4dd3ae03d7fe1052@mail.gmail.com","subject":"Re: (beginner) git rm","fromName":"Björn Steinbrink","fromEmail":"b.steinbrink@gmx.de","sentAt":"2009-01-29T02:34:32Z","receivedAt":"2009-01-29T02:34:32Z","isPatch":false,"sender":{"key":"b.steinbrink@gmx.de","avatar":"https://avatars.githubusercontent.com/u/230962?v=4"},"body":"On 2009.01.28 17:11:07 -0800, Jonathan Wills wrote:\n> This seems like an appropriate thread to ask something I came across today.\n> Either I am unclear about the precise semantics of git checkout <branch>\n> <path>, or there is a bug in said command.  I noticed this when I wanted to\n> get a directory to match the same directory in another branch, so I did rm\n> -rf dir, followed by git checkout master dir.  Afterwards I noticed that\n> files in that directory that had previously been in my branch but were not\n> in the master branch had returned.  Earlier in this thread it was mentioned\n> that git checkout will not remove files, but in this case I had already\n> removed those files and git checkout actually replaced them (and not from\n> the master branch like I asked, but from the current branch).\n\nThis is exactly what I meant. Your \"rm -rf dir\" only removed the\ndirectory from the working tree, but _not_ from the index. And what\n\"git checkout master -- dir\" then does is that it puts all the stuff\nthat is in master's \"dir\" into the index, in _addition_ to the stuff\nalready in the index. And then it puts everything from the index's \"dir\"\ninto the working tree. This is really a two step process and in each\nstep the pathspec is matched separately.\n\nSo the working tree doesn't have \"dir\" at all.\n\nIn the index you still have:\nwhatever\ndir/file (index version)\ndir/other_file\n\nIn master you have:\nwhatever_2\ndir/file (master version)\ndir/yet_another_file\n\nThen you do \"git checkout master -- dir\".\n\nIn the first step, that \"dir\" pathspec matches these files from master:\ndir/file\ndir/yet_another_file\n\nSo those are added to the index, and the index will have:\nwhatever\ndir/file (master version)\ndir/other_file\ndir/yet_another_file\n\nSo \"dir/file\" was replaced, and \"dir/yet_another_file\" was added. But\n\"dir/other_file\" is still around.\n\nAnd then comes the index -> working tree step. The pathspec matches all\nthree files in \"dir\" in the index, and so they appear in the working\ntree.\n\n\nTo get what you expected, you have several options:\na)\nrm -rf dir\ngit add -u dir (drops it from the index)\ngit checkout master -- dir\n\nb)\ngit rm -rf dir\ngit checkout master -- dir\n\nJust saves the \"git add -u\" step.\n\nc)\nrm -rf dir\ngit reset master -- dir\ngit checkout -- dir\n\nThe reset makes \"dir\" in the index equal to master's \"dir\" (ok,\ntechnically that's wrong, as the index doesn't even know about \"dir\" on\nits own, but my brain fails to produce a correct description).\n\nBjörn\n"}]}