(oops, emc-users got left off on the To: line, I added it back on) On Sep 30, 2011, at 03:04 , andy pugh wrote:
> On 30 September 2011 03:09, Sebastian Kuzminsky <s...@highlab.com> wrote: > >> When you went to push your v2.5_branch, git informed you that your >> v2.5_branch had diverged from origin's. You probably did "git pull" at that >> point, which is shorthand for "git fetch; git merge", and that's where your >> extra merge came from: "git pull" merged origin/v2.5_branch (with Chris and >> Dewey's commits) into your local v2.5_branch with your new commits. You >> pushed the result and here it is, gracing our shared repo for all time. ;-) > > Oh. Yes, that would be it. Makes sense now. > At that point I should have reset my tracking branch, updated, then > cherry-picked the commits out of the working branch again before the > push? I wouldn't do it that way. Let's say I'm working on my local branch "my-branch", based on origin/v2.5_branch, and it's in good shape and I want to push it to origin to share with the rest of the group. I say "git push" and if it complains about divergence, here's what I do: First of all: "git fetch" (seeing a trend here?) That copies the new history from origin into my local repo without messing with any of my local stuff. This is required so I can see what's happened in the origin repo to cause the divergence. Then: "git rebase origin/v2.5_branch" That's like a shorthand for cherry-picking all the my-branch commits on to the tip of origin/v2.5_branch, but way less susceptible to human error. Then: "git push origin my-branch:v2.5_branch", and it should work now, because my-branch is a fast-forward from origin/v2.5_branch. > I wish there was an (easy) git-undo. There is! As long as you haven't shared, meaning as long as you haven't pushed to where anyone else can see it. Actually there are several undoes, for different values of "undo": You can "git commit --amend" to modify the previous commit. You can "git reset --hard $A_BETTER_PLACE", to move the branch tip to a better place. For example, to throw away the most recent commit: "git reset --hard HEAD^". You can "git rebase -i", and edit any commit in your history. Or reorder commits, split a commit in two, combine two commits into one, edit commit messages, etc. It's awesome. I use this a *lot* when working on non-trivial private branches. In the beginning of the development i commit often, a bunch of bogus commits that i'd be embarrassed to show you guys, but I still want to keep track of my crazy stream-of-consciousness changes. As the branch is starting to take a reasonable shape, i go back and use "rebase -i" to clean up the history and make it look like i knew all along what I was doing. :-) There are probably more "git undo" commands, but "git rebase -i" takes care of 99% of my needs so I'll stop there. :-) -- Sebastian Kuzminsky ------------------------------------------------------------------------------ All of the data generated in your IT infrastructure is seriously valuable. Why? It contains a definitive record of application performance, security threats, fraudulent activity, and more. Splunk takes this data and makes sense of it. IT sense. And common sense. http://p.sf.net/sfu/splunk-d2dcopy2 _______________________________________________ Emc-users mailing list Emc-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/emc-users