* RE: git -- how to revert build to as-originally-cloned? @ 2011-05-20 16:25 George Spelvin 2011-05-20 19:18 ` John Lumby 0 siblings, 1 reply; 11+ messages in thread From: George Spelvin @ 2011-05-20 16:25 UTC (permalink / raw) To: git, johnlumby, timmazid; +Cc: linux Ah - I should have said that I selected only merges in my git log command - git log --merges (With no qualifier, git log returns about 3.8 million lines / 150 MBytes, hard to work with) > And, based on what the command now returns, it seems that the first two > that I listed before (which are no longer present) were as a result of my > (single) merge command, i.e. my merge resulted in merging : > . two merges that were done by someone else in the master that I > cloned into my /b filesystem, > . maybe some other non-merge commits that I did not query before > and now don't know Er, no. One "git merge" command produces (at most) one commit. It may be that the head of the branch you merged in was already a merge commit, but tha You may find "gitk" useful for for visualizing all of this. > You've lost me here. If a merge can consist of many commits, > including other merges (see above), then how can one commit be a merge? > Note that in my original git log --merges output that I posted in my > earlier post, i.e. the one before I reset, there was *no* record of *my* > merge command itself, only of the sub-merges that my merge dragged along. > I think this is the crucial (to me) point - git did not record what I did, > only the effects of what I did. Not saying this is wrong or right, > but significant. Okay, here's the basic confusion. Commits have pointers to other commits, and are organized into a linked list. (Actually, a directed acyclic graph, since a commit can have more than one ancestor pointer.) Thus, a commit identifies *both* a single snapshot *and* a complete development history. We tend to talk about a "commit" when describing the former, and "branch" when talking about the latter, but they're actually the same object. A merge *is* exactly one commit. A "merge commit" is just a commit with more than one ancestor. Now, that merge can *point to* lots of other commits, but it doesn't exactly "consist of" them. The other thing is that the ancestors of a merge are symmetrical. They are numbered for reference, but the practical results of "merge A with B" and "merge B with A" are identical. Every commit points to the full development history that produced it. Now, what might have happened to you was a "fast forward" merge. If you have a history like this: o--o--o--a--b--c--d And you ask git to merge a and d together, the result will be simply d. Git, by default, avoids creating useless merges in such a case. So if you merge in someone else's work, and you haven't done anything locally since their branch split off from your HEAD, the result will not include a merge commit at all. (A NEW merge commit; they branch might include merge commits.) Since the top merges in your example are by Dave Miller (and not by you), it looks like that's what happened in this case. ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: git -- how to revert build to as-originally-cloned? 2011-05-20 16:25 git -- how to revert build to as-originally-cloned? George Spelvin @ 2011-05-20 19:18 ` John Lumby 2011-05-20 19:34 ` Paul Ebermann 2011-05-20 20:22 ` George Spelvin 0 siblings, 2 replies; 11+ messages in thread From: John Lumby @ 2011-05-20 19:18 UTC (permalink / raw) To: George Spelvin; +Cc: git, timmazid On 05/20/11 12:25, George Spelvin wrote: > Er, no. One "git merge" command produces (at most) one commit. > It may be that the head of the branch you merged in was already > a merge commit, but tha > > You may find "gitk" useful for for visualizing all of this. I have tried gitk. Can you or someone tell me what the colours of the nodes in the top left signifies? Specifically, a commit of mine (done since all the merging I've been asking about) shows as yellow, whereas all the ones prior to that show as blue. (I have not altered or changed the colour scheme so it's whatever the default is) > > A merge *is* exactly one commit. A "merge commit" is just a commit with > more than one ancestor. Now, that merge can *point to* lots of other > commits, but it doesn't exactly "consist of" them. > > > > Now, what might have happened to you was a "fast forward" merge. Yes! actually in the output of the merge command (that I showed in my original posting) it said Updating 72a8f97..1b1cb1f Fast-forward > If you have a history like this: > > o--o--o--a--b--c--d > > And you ask git to merge a and d together, the result will be simply d. > Git, by default, avoids creating useless merges in such a case. So if > you merge in someone else's work, and you haven't done anything locally > since their branch split off from your HEAD, the result will not include > a merge commit at all. (A NEW merge commit; they branch might include > merge commits.) > > Since the top merges in your example are by Dave Miller (and not by you), > it looks like that's what happened in this case. Yes indeed, thanks for explaining. So what would be the correct way, before doing my fast-forward merge, to have made some kind of mark pointing at "a", which I could then have used to undo the fast-forward, without having to calculate the number of commits in between? (supposing my branch was not anchored at "a" but at some much earlier point)? Cheers, John Lumby ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: git -- how to revert build to as-originally-cloned? 2011-05-20 19:18 ` John Lumby @ 2011-05-20 19:34 ` Paul Ebermann 2011-05-20 20:22 ` George Spelvin 1 sibling, 0 replies; 11+ messages in thread From: Paul Ebermann @ 2011-05-20 19:34 UTC (permalink / raw) To: John Lumby; +Cc: git John Lumby schrieb: > On 05/20/11 12:25, George Spelvin wrote: >> Er, no. One "git merge" command produces (at most) one commit. >> It may be that the head of the branch you merged in was already >> a merge commit, but tha >> >> You may find "gitk" useful for for visualizing all of this. > > I have tried gitk. Can you or someone tell me what the colours of the > nodes in the top left signifies? > Specifically, a commit of mine (done since all the merging I've been > asking about) shows as yellow, whereas all the ones prior to that > show as blue. (I have not altered or changed the colour scheme so > it's whatever the default is) For the nodes: Yellow is the current HEAD. Red is your worktree, if differing from the index, green is the index, if differing from HEAD. Everything else (in blue) are other commits in the repository. The color of the lines is not significant, I think (or at least I didn't recognize any regularity here). (This is for my version of gitk, whichever this might be. I didn't find a way to find out. It says "(c) 2005-2010" in the "about" dialog and "(c) 2005-2009" in the start of the source code. Paŭlo ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: git -- how to revert build to as-originally-cloned? 2011-05-20 19:18 ` John Lumby 2011-05-20 19:34 ` Paul Ebermann @ 2011-05-20 20:22 ` George Spelvin 2011-05-20 20:26 ` George Spelvin 1 sibling, 1 reply; 11+ messages in thread From: George Spelvin @ 2011-05-20 20:22 UTC (permalink / raw) To: johnlumby, linux; +Cc: git, timmazid > I have tried gitk. Can you or someone tell me what the colours of > the nodes in the top left signifies? Specifically, a commit of mine > (done since all the merging I've been asking about) shows as yellow, > whereas all the ones prior to that show as blue. Nothing. It just tries to use different colours so you can tell the lines apart. But the specific colour is no more meaningful than shadings on a map. > So what would be the correct way, before doing my fast-forward merge, > to have made some kind of mark pointing at "a", which I could then have > used to undo the fast-forward, without having to calculate the number > of commits in between? (supposing my branch was not anchored at "a" > but at some much earlier point)? The basic tool to do that is "git tag <name>", which creates a tag with the given name. (The difference between a tag and a branch is simply that a branch is updated when you commit.) However, most people don't bother with an explicit name; see the man page for git-rev-parse for a list of all the ways to refer to old revisions. @{1} is the usual syntax for "the current branch before the last change", or you can use the older name ORIG_HEAD, too. "git reflog" will show an extended history. ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: git -- how to revert build to as-originally-cloned? 2011-05-20 20:22 ` George Spelvin @ 2011-05-20 20:26 ` George Spelvin 0 siblings, 0 replies; 11+ messages in thread From: George Spelvin @ 2011-05-20 20:26 UTC (permalink / raw) To: johnlumby, linux; +Cc: git, timmazid >> I have tried gitk. Can you or someone tell me what the colours of >> the nodes in the top left signifies? Specifically, a commit of mine >> (done since all the merging I've been asking about) shows as yellow, >> whereas all the ones prior to that show as blue. George Spelvin wrote, in a fit of insanity: > Nothing. It just tries to use different colours so you can tell the > lines apart. But the specific colour is no more meaningful than > shadings on a map. Correction: What Pual Ebermann said. I was talking about the colour of the LINES. I didn't read your question carefully enough. My apologies. ^ permalink raw reply [flat|nested] 11+ messages in thread
* git -- how to revert build to as-originally-cloned? @ 2011-05-18 22:53 John Lumby 2011-05-18 23:26 ` Tim Mazid 2011-05-20 14:42 ` Philippe Vaucher 0 siblings, 2 replies; 11+ messages in thread From: John Lumby @ 2011-05-18 22:53 UTC (permalink / raw) To: git I am stuck trying to revert a private kernel build back to the state in which I originally cloned it, (after probably doing the wrong thing - as below). Hoping someone can advise. Here's what I did (helpful criticism welcome) On machine MA in filesystem /a on 13 May git clone git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next-2.6.git (This build built ok and ran ok and is what I want back) A few days later on machine MB on filesystem /b - same git clone command but of course a slightly changed build. Yesterday - I wanted to synch build a/ from b/ : git branch jel_r8169 /* made a new branch -- ok */ nfs-mounted /b on MA git fetch file:///a/.../net-next-2.6/.git /* worked ok * git merge FETCH_HEAD /* worked ok and output list of files : */ output started with Updating 72a8f97..1b1cb1f Fast-forward then list of files output ended with 56 files changed, 3352 insertions(+), 886 deletions(-) create mode 100644 include/net/ping.h create mode 100644 net/ipv4/ping.c I then built this build and built ok but build is broken - unresolved syms in some modules - I want to undo my merge. I have tried all the commands I can find that claim to do this and none of them have done it, e.g. : git reset --hard HEAD /* did nothing */ git reset --hard ORIG_HEAD /* did nothing */ Not only that, but none of the various show , log , status commands appear to be aware of the merge at all. There appears to be no record of it - but the actual files themselves are the updated ones. (diff with /b compares equal) How can I undo it? Cheers John Lumby ^ permalink raw reply [flat|nested] 11+ messages in thread
* RE: git -- how to revert build to as-originally-cloned? 2011-05-18 22:53 John Lumby @ 2011-05-18 23:26 ` Tim Mazid 2011-05-19 15:27 ` John Lumby 2011-05-20 14:42 ` Philippe Vaucher 1 sibling, 1 reply; 11+ messages in thread From: Tim Mazid @ 2011-05-18 23:26 UTC (permalink / raw) To: johnlumby, Git Mailing List > Date: Wed, 18 May 2011 18:53:01 -0400 > From: johnlumby@hotmail.com > To: git@vger.kernel.org > Subject: git -- how to revert build to as-originally-cloned? > > I am stuck trying to revert a private kernel build back to the state in > which I originally cloned it, > (after probably doing the wrong thing - as below). Hoping someone > can advise. > > Here's what I did (helpful criticism welcome) > > On machine MA in filesystem /a on 13 May > > git clone > git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next-2.6.git > ... > > I have tried all the commands I can find that claim to do this > and none of them have done it, e.g. : > git reset --hard HEAD /* did nothing */ > git reset --hard ORIG_HEAD /* did nothing */ > > Not only that, but none of the various show , log , status commands > appear to be aware of the merge at all. There appears to be no record > of it - > but the actual files themselves are the updated ones. (diff with /b > compares equal) > > How can I undo it? > > Cheers John Lumby You should now have a merge commit. git log should show the latest commit with a message similar to "merge blah". Normally in order to undo a merge, you would simply do a "git reset --hard HEAD^". Take note of the carat(is that correct?) character; that means the commit BEFORE head. Can you please post the commit message that you see in the first commit when doing a git log? Also, if you just want to go back to a particular branch, you can specify it to git reset, in the form of "git reset --hard origin/master". This will reset (discarding any changes) YOUR branch to wherever origin/master happens to be, which, from reading your message seems to be where you want to go? Be careful if you have made changes you want to keep, though. Cheers, Tim. () ascii ribbon campaign - against html e-mail /\ www.asciiribbon.org - against proprietary attachments ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: git -- how to revert build to as-originally-cloned? 2011-05-18 23:26 ` Tim Mazid @ 2011-05-19 15:27 ` John Lumby 2011-05-20 2:16 ` Tim Mazid 0 siblings, 1 reply; 11+ messages in thread From: John Lumby @ 2011-05-19 15:27 UTC (permalink / raw) To: Tim Mazid; +Cc: Git Mailing List On 05/18/11 19:26, Tim Mazid wrote: >> Date: Wed, 18 May 2011 18:53:01 -0400 >> From: johnlumby@hotmail.com >> To: git@vger.kernel.org >> Subject: git -- how to revert build to as-originally-cloned? >> >> I am stuck trying to revert a private kernel build back to the state in >> which I originally cloned it, > > > Normally in order to undo a merge, you would simply do a "git reset > > --hard HEAD^". Take note of the carat(is that correct?) character; that > > means the commit BEFORE head. > > > > Can you please post the commit message that you see in the first commit > > when doing a git log? Here are the first three. I assume (not sure) they are what was merged into the newer clone, /b, just before I cloned it ------------------------------------------------------------------------------ commit 89c64d755fbf04d7541d526931dc4b38301946d1 Merge: 4dc6ec2 4f6290c Author: David S. Miller <davem@davemloft.net> Date: Sun May 15 01:08:23 2011 -0400 Merge branch 'master' of master.kernel.org:/pub/scm/linux/kernel/git/jkirsher/net-next-2.6 commit 4dc6ec26fe7d9f89349d4c0c654e2f07420f4b27 Merge: 7be799a ca06c6e Author: David S. Miller <davem@conan.davemloft.net> Date: Sat May 14 22:47:51 2011 -0400 Merge branch 'batman-adv/next' of git://git.open-mesh.org/ecsv/linux-merge commit 5c5095494fb545f53b80cbb7539679a10a3472a6 Merge: 4d586b8 def5768 Author: David S. Miller <davem@davemloft.net> Date: Thu May 12 23:01:55 2011 -0400 ------------------------------------------------------------------------------ So I now think I see the problem with using a reset based on something relating to commits - apparently (??) there is nothing in the git log to distinguish commits done by my last merge versus commits prior to that. I.e. the "merge" does not appear to be logged as an event in its own right, only as the commits inside it?? > Also, if you just want to go back to a particular branch, you can > specify it to git reset, in the form of "git reset --hard > origin/master". This will reset (discarding any changes) YOUR branch to > wherever origin/master happens to be, which, from reading your message > seems to be where you want to go? Ah - that did it, thanks Tim. I had seen that one but wasn't sure whether it would reset me back to what I cloned or the master of that clone i.e. way back to the "original" origin of this build. It seems if I had not created a separate branch -- I would now be completely sunk? It would be nice if there was a "git undo" which undid whatever changes to files+index were made by the immediately preceding git command, whatever it was and whatever it did. > Be careful if you have made changes you want to keep, though. No worries there although thanks for the warning. ^ permalink raw reply [flat|nested] 11+ messages in thread
* RE: git -- how to revert build to as-originally-cloned? 2011-05-19 15:27 ` John Lumby @ 2011-05-20 2:16 ` Tim Mazid 2011-05-20 14:15 ` John Lumby 0 siblings, 1 reply; 11+ messages in thread From: Tim Mazid @ 2011-05-20 2:16 UTC (permalink / raw) To: johnlumby; +Cc: Git Mailing List I think I'll just give a brief answer to each of your points, then give you a wall of text at the end. > From: johnlumby@hotmail.com > On 05/18/11 19:26, Tim Mazid wrote: > > Normally in order to undo a merge, you would simply do a "git reset > > --hard HEAD^". Take note of the carat(is that correct?) character; that > > means the commit BEFORE head. HEAD points at the commit where you are checked out now. The carat character '^' tells git to look at the commit BEFORE the one that's specified. See below. > > Can you please post the commit message that you see in the first commit > > when doing a git log? > > Here are the first three. I assume (not sure) they are what was merged > into the newer clone, /b, just before I cloned it > > ------------------------------------------------------------------------------ > commit 89c64d755fbf04d7541d526931dc4b38301946d1 > Merge branch 'master' of > master.kernel.org:/pub/scm/linux/kernel/git/jkirsher/net-next-2.6 > > commit 4dc6ec26fe7d9f89349d4c0c654e2f07420f4b27 > Merge branch 'batman-adv/next' of > git://git.open-mesh.org/ecsv/linux-merge > > commit 5c5095494fb545f53b80cbb7539679a10a3472a6 > ------------------------------------------------------------------------------ You actually skipped the message of the third message there. :P But I can see that the first two are actually merges. Were they both your doing? If so, doing a git reset --hard HEAD^ will only take you back one commit. See above, and then below. > So I now think I see the problem with using a reset based on something > relating to commits - > apparently (??) there is nothing in the git log to distinguish commits > done by my last merge versus commits prior to that. I.e. the "merge" > does not appear to be logged as an event in its own right, only as the > commits inside it?? Two points: - in git, you have commits and "pointers to commits"; and - the commit itself IS the merge. See below. > > Also, if you just want to go back to a particular branch, you can > > specify it to git reset, in the form of "git reset --hard > > origin/master". This will reset (discarding any changes) YOUR branch to > > wherever origin/master happens to be, which, from reading your message > > seems to be where you want to go? > > Ah - that did it, thanks Tim. I had seen that one but wasn't > sure whether it would reset me back to what I cloned or the master of > that clone i.e. way back to the "original" origin of this build. > > It seems if I had not created a separate branch -- I would now be > completely sunk? Your branches are completely separate to the branches of other repos. See below. > It would be nice if there was a "git undo" which undid whatever changes > to files+index were made by the immediately preceding git command, > whatever it was and whatever it did. I believe (speculation) that the reason this hasn't been done is that there are too many things you can _DO_ in git in order to have a simple "undo" button. Compare it to having an "undo" button in real life; what and how much would it actually undo? There are simply too many different situations to have something as simple as undo. Having said that, there are ways to recover from almost every situation in git (most of which I'm yet to learn). See below. > > Be careful if you have made changes you want to keep, though. > No worries there although thanks for the warning. I've lost data a few times not thinking about what I was doing. :P Alright, so I promised you a crack at an explanation. List, please feel free to chime in and correct me where I am mistaken. All changes that you make to your repository are stored in what are called "commits"; these are, essentially diffs, and point to "parent" and "child" commits, so that you can trace a path along commits and see your code change along the way. Now, branches and tags are actually "pointers to commits"[*] in a way. A branch or a tag in itself does not actually contain any changes or code. When you reference a branch or tag, you're actually referencing the commit that they point to. When you create a tag, you give it a commit that it should point to (if you do not provide a commit, it actually defaults to where you are now), and then the tag never changes. This is why it is useful for "tagging"[*] releases. You put it there and it will stay there so that other people can see it. In this way, it is permanent[*] (unless you really want to delete it). Branches, however, are different; whenever you checkout a branch, whatever you do, whether it may be resetting, creating new commits, or merges, the branch follows you around, such that it records your actions as being part of that branch. So a branch will "flow"[*] over time as you add more code. Thus, branches are semi-permanent[*], as the commits they point to change, but they stay in the "past" of the branch. Things like HEAD and FETCH_HEAD are similar in that they too "point at commits", but unlike branches (which are semi-permanent) and tags (which are permanent), they are temporary. HEAD moves around; a _lot_. What HEAD really does is point to the commit that you are checked out on. Whenever you switch branches, move around, make commits, merges, and whatever else, HEAD keeps changing to point at the commit you are now on, whether it be a previously existing one, or a newly created one. So, in your repository, you have branches, and tags, and a bunch of temporary pointers, such as HEAD. So does everybody else. How do you tell which is which? Well, that is why when I told you to git reset, I told you to tell it to point to "origin/master". What that means is the pointer named "master" on the remote repository called "origin". (More on remote repositories later). If you had said "git reset --hard master" it actually would have reset you to _your_ master branch. If you were already checked out on master, you would've gone nowhere. So, "git reset --hard branch-name" takes whatever branch you're on, and makes it point to the same place as branch-name, which exists in your local repository. As a corollary, "git reset --hard remote-name/branch-name" takes the branch you're on, and makes it point to the same place as branch-name on the _remote_ repository named remote-name. (More on remote repositories shortly). If you were to do, however, "git reset --hard HEAD", you don't actually move to anywhere; but what it does do, because you've supplied the "--hard" option, is *discards* _all_ changes made from the commit that HEAD points at. This means that if you have made any changes, but have not committed them, they will be lost. This is useful if you made some changes which you decide you don't need, or if you were merely testing something in your code. But use it with caution, as you will _all_ changes; so if you made some changes, but decided you didn't want to keep some, commit what you want to keep first. But what if you did a merge or already committed some changes, and want to undo that? Well, that is where the modifiers[*] come in. The one you've already been introduced to is the carat character (^). What this actually means is point to the commit _before_ the one referenced. So, saying HEAD^ means the commit before HEAD. And because merges are actually commits, you can easily undo a merge by going to the commit just before it. You can also chain carats together; HEAD^^^ means the commit *three* before where HEAD points. You can also use carats for other commit references[*], such as branches and tags. Want to go to the commit just before v1.0 (for whatever reason)? No problem. Just do a "git checkout v1.0^". But, what if you want to go to the commit ten or twenty before v1.0? The first thing I would say is that is far too specific without actually knowing where you're going and you should reconsider your strategy. However, if that is what you wish to do, you could easily stack twenty carats together. You can see that this would be very unwieldy; that is why git provides us with another modifier: the tilde (~). You must always follow the tilde with a number. What it says is that you want to go X commits before the referenced one. So, "git checkout v1.0~17" will take you to the commit *17* before v1.0. I said before that that you have your local repository and the remote repository. You can actually have any number of remote repositories referenced. Initially, though, the only remote repository you have is the one where you checked out from (unless you created a clean repo yourself). You can add and remove remote repositories through the "git remote" command. You were afraid about not creating a branch and being sunk. The important thing to realise is that whatever you do in _your_ repository does not affect the _remote_ repository. The information in the remote repository will stay there until _they_ decide to change it. So the only way for you to affect the remote repository is for them to take what you did and apply it to their repository. Secondly, even given that, your remote pointers (the origin/* pointers) cannot be changed by you. All you can do is remove them (you can add them back at any point; this is not a loss) and synchronise[*] them with the remote, if they've changed there. This means that no matter what you did, unless you actually deleted the origin/master remote branch (which you could easily get back anyway), the "git reset --hard origin/master" command will always take you back to your happy place, or, more correctly, where the remote was pointing its master branch to when you last synchronised. You can view all the remote branches you can reference by using the "git branch -r" command, without any arguments. You can also view all your local branches by using "git branch" (without the -r). It works similarly for "git tag". I hope I've covered everything you wanted. If not, there are plenty of resources, and you can always ask here. It also helps to visualise these things, and there are several tools that help you in this regard. The first is "git log --graph", which will show you lines on the side, showing you how commits are connected. Then, there are a number of external programs. I personally use gitk, but I know there are others, if it doesn't suit your tastes. And have a read through the documentation. You probably won't understand most of it the first time, but the more you read it, the more you'll understand. Good luck, Tim. () ascii ribbon campaign - against html e-mail /\ www.asciiribbon.org - against proprietary attachments ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: git -- how to revert build to as-originally-cloned? 2011-05-20 2:16 ` Tim Mazid @ 2011-05-20 14:15 ` John Lumby 0 siblings, 0 replies; 11+ messages in thread From: John Lumby @ 2011-05-20 14:15 UTC (permalink / raw) To: Tim Mazid; +Cc: Git Mailing List Tim, Thanks very much indeed for taking the time to provide all that explanation. Very helpful. Not sure I have understood all of it but it makes more sense now. I will embed answers to specific questions you raised : On 05/19/11 22:16, Tim Mazid wrote: > >>> Can you please post the commit message that you see in the first commit >>> when doing a git log? >> Here are the first three. I assume (not sure) they are what was merged >> into the newer clone, /b, just before I cloned it >> >> ------------------------------------------------------------------------------ >> commit 89c64d755fbf04d7541d526931dc4b38301946d1 >> Merge branch 'master' of >> master.kernel.org:/pub/scm/linux/kernel/git/jkirsher/net-next-2.6 >> >> commit 4dc6ec26fe7d9f89349d4c0c654e2f07420f4b27 >> Merge branch 'batman-adv/next' of >> git://git.open-mesh.org/ecsv/linux-merge >> >> commit 5c5095494fb545f53b80cbb7539679a10a3472a6 >> ------------------------------------------------------------------------------ > You actually skipped the message of the third message there. :P You're right. as it happens, after the reset back to origin/master, that third merge is now the first one shown in the log and it reads commit 5c5095494fb545f53b80cbb7539679a10a3472a6 Merge: 4d586b8 def5768 Author: David S. Miller <davem@davemloft.net> Date: Thu May 12 23:01:55 2011 -0400 Merge branch 'master' of master.kernel.org:/pub/scm/linux/kernel/git/davem/net-next-2.6 > But I can see that the first two are actually merges. Were they both > your doing? If so, doing a git reset --hard HEAD^ will only take you > back one commit. > See above, and then below. Ah - I should have said that I selected only merges in my git log command - git log --merges (With no qualifier, git log returns about 3.8 million lines / 150 MBytes, hard to work with) And, based on what the command now returns, it seems that the first two that I listed before (which are no longer present) were as a result of my (single) merge command, i.e. my merge resulted in merging : . two merges that were done by someone else in the master that I cloned into my /b filesystem, . maybe some other non-merge commits that I did not query before and now don't know > >> So I now think I see the problem with using a reset based on something >> relating to commits - >> apparently (??) there is nothing in the git log to distinguish commits >> done by my last merge versus commits prior to that. I.e. the "merge" >> does not appear to be logged as an event in its own right, only as the >> commits inside it?? > Two points: > - in git, you have commits and "pointers to commits"; and > - the commit itself IS the merge. You've lost me here. If a merge can consist of many commits, including other merges (see above), then how can one commit be a merge? Note that in my original git log --merges output that I posted in my earlier post, i.e. the one before I reset, there was *no* record of *my* merge command itself, only of the sub-merges that my merge dragged along. I think this is the crucial (to me) point - git did not record what I did, only the effects of what I did. Not saying this is wrong or right, but significant. > See below. > > >>> Also, if you just want to go back to a particular branch, you can >>> specify it to git reset, in the form of "git reset --hard >>> origin/master". This will reset (discarding any changes) YOUR branch to >>> wherever origin/master happens to be, which, from reading your message >>> seems to be where you want to go? >> Ah - that did it, thanks Tim. I had seen that one but wasn't >> sure whether it would reset me back to what I cloned or the master of >> that clone i.e. way back to the "original" origin of this build. >> >> It seems if I had not created a separate branch -- I would now be >> completely sunk? > Your branches are completely separate to the branches of other repos. Ah, ok. Good. > See below. > > >> It would be nice if there was a "git undo" which undid whatever changes >> to files+index were made by the immediately preceding git command, >> whatever it was and whatever it did. > I believe (speculation) that the reason this hasn't been done is that > there are too many things you can _DO_ in git in order to have a simple > "undo" button. Compare it to having an "undo" button in real life; what > and how much would it actually undo? There are simply too many different > situations to have something as simple as undo. > Having said that, there are ways to recover from almost every situation > in git (most of which I'm yet to learn). See below. I see it would be a large and tedious thing to code, but I do think it would be perfectly well-defined : gather all relevant information about the most recent git command that changed either files or index or pointers, and reverse its effects. In my particular case, with your insight, I can now see that it would have been quite easy to delve into the log and calculate how many carets or tildes I needed to revert back to the commit that corresponded to my initial cloned state. In a general case, I think this could easily be a complex burden for a dumb user to have to do compared with "undo what I just did". > >>> Be careful if you have made changes you want to keep, though. >> No worries there although thanks for the warning. > I've lost data a few times not thinking about what I was doing. :P > > > Alright, so I promised you a crack at an explanation. List, please feel > free to chime in and correct me where I am mistaken. > > Yes, I have used gitk and it helps a lot. Thanks again John Lumby ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: git -- how to revert build to as-originally-cloned? 2011-05-18 22:53 John Lumby 2011-05-18 23:26 ` Tim Mazid @ 2011-05-20 14:42 ` Philippe Vaucher 1 sibling, 0 replies; 11+ messages in thread From: Philippe Vaucher @ 2011-05-20 14:42 UTC (permalink / raw) To: John Lumby; +Cc: git > am stuck trying to revert a private kernel build back to the state in which I originally cloned it, > (after probably doing the wrong thing - as below). Hoping someone can advise. I just wanted to add that usually when I "mess up" and want to revert to a previous state, I usually simply `git reflog`, find where I was before messing up, then `git reset --hard` to the desired SHA1. Hope it helps, Philippe ^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2011-05-20 20:26 UTC | newest] Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2011-05-20 16:25 git -- how to revert build to as-originally-cloned? George Spelvin 2011-05-20 19:18 ` John Lumby 2011-05-20 19:34 ` Paul Ebermann 2011-05-20 20:22 ` George Spelvin 2011-05-20 20:26 ` George Spelvin -- strict thread matches above, loose matches on Subject: below -- 2011-05-18 22:53 John Lumby 2011-05-18 23:26 ` Tim Mazid 2011-05-19 15:27 ` John Lumby 2011-05-20 2:16 ` Tim Mazid 2011-05-20 14:15 ` John Lumby 2011-05-20 14:42 ` Philippe Vaucher
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.