{"thread":{"id":"23634","subject":"How to undo changes?","startedAt":"2010-04-29T01:08:19Z","lastAt":"2010-04-29T01:29:25Z","messageCount":2,"participants":["Lin Mac","Erik Faye-Lund"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"140619","messageId":"l2l10d816431004281808s79a559e6p308052c788c9a4ca@mail.gmail.com","threadId":"23634","inReplyTo":null,"subject":"How to undo changes?","fromName":"Lin Mac","fromEmail":"mkl0301@gmail.com","sentAt":"2010-04-29T01:08:19Z","receivedAt":"2010-04-29T01:08:19Z","isPatch":false,"sender":{"key":"mkl0301@gmail.com","avatar":null},"body":"Hi,\n\n1.\nI have multiple files modified, but would like to undo the changes in\none of the changed files.\n\"git reset --hard\" do not accept single files. So I used to use \"git\ndiff <file> | patch -p X\", but X cannot be know until I checked the\npatch and know the path relationship. Is there other way to do it?\n\n2.\nSometimes I delete old unused branches with \"git branch -D <branch>\",\nbut I just realized theren't a reflog log for such operation. If the\nbranch is the only reference to the logs, deleting the branch makes\nthe commits become dangling commits.  How could I recover those\ncommit?\n\nI run into situation 1 from time to time. Luckily I have never ran\ninto situation 2, but would like to know the recovery ways.\nThanks in advance.\n\nBest Regards,\nMac Lin\n"},{"id":"140620","messageId":"g2z40aa078e1004281829o446bce44r165aa59c98969043@mail.gmail.com","threadId":"23634","inReplyTo":"l2l10d816431004281808s79a559e6p308052c788c9a4ca@mail.gmail.com","subject":"Re: How to undo changes?","fromName":"Erik Faye-Lund","fromEmail":"kusmabite@googlemail.com","sentAt":"2010-04-29T01:29:25Z","receivedAt":"2010-04-29T01:29:25Z","isPatch":false,"sender":{"key":"kusmabite@gmail.com","avatar":"https://avatars.githubusercontent.com/u/47073?v=4"},"body":"On Thu, Apr 29, 2010 at 3:08 AM, Lin Mac <mkl0301@gmail.com> wrote:\n> Hi,\n>\n> 1.\n> I have multiple files modified, but would like to undo the changes in\n> one of the changed files.\n> \"git reset --hard\" do not accept single files. So I used to use \"git\n> diff <file> | patch -p X\", but X cannot be know until I checked the\n> patch and know the path relationship. Is there other way to do it?\n\ngit checkout -- <file>\n\n>\n> 2.\n> Sometimes I delete old unused branches with \"git branch -D <branch>\",\n> but I just realized theren't a reflog log for such operation. If the\n> branch is the only reference to the logs, deleting the branch makes\n> the commits become dangling commits.  How could I recover those\n> commit?\n>\n\nRun \"git fsck --lost-found\" to list the SHA-1s of all dangling objects.\n\nBut make sure you've taken a backup of the repo first, just in case\nsomething gets messed up further ;)\n\n-- \nErik \"kusma\" Faye-Lund\n"}]}