{"thread":{"id":"26334","subject":"Confused about git filter-branch results","startedAt":"2011-01-25T11:48:40Z","lastAt":"2011-01-26T11:18:35Z","messageCount":3,"participants":["Mike Kelly","Thomas Rast"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"159850","messageId":"20110125114840.GB9367@skull.piratehaven.org","threadId":"26334","inReplyTo":null,"subject":"Confused about git filter-branch results","fromName":"Mike Kelly","fromEmail":"mike@piratehaven.org","sentAt":"2011-01-25T11:48:40Z","receivedAt":"2011-01-25T11:48:40Z","isPatch":false,"sender":{"key":"mike@piratehaven.org","avatar":null},"body":"Hi Everyone,\n\nI was fooling around with 'git filter-branch --env-filter ...' trying to\nupdate the timestamps on my commits (which worked), but now when I run\n'git whatchanged -p master..' shows all changes to the entire project, not\nthe differences between my branch and the master branch.\n\nBeing a novice git user, I'm not sure how much to trust that I didn't hose\ngit in some really weird way, leaving it in a state where it doesn't quite\nwork the way it did before.\n\nThe contents of .git/refs/original/refs/heads/ shows a file with my branch\nname which contains only one entry (presumably the one I updated the\ntimestamp on) so I feel pretty sure that only the commit I wanted to change\nactually changed.  However, the fact that 'git whatchanged -p' now behaves\ndifferently makes me worry.\n\nNothing went wrong during my update, however, I forgot to give a range\nlabel so it searched the entire project.  In theory nothing should have\nchanged, but...\n\nUltimately, my worry is that I polluted the history which I cloned, and\npushing that would make people unhappy.\n\nI can still get to my patches, so I can still do a fresh pull and reapply\nall my changes again, as a last resort, but I'd rather not if I don't\nhave to.\n\nSo my questions are:\n 1) Is this a problem with an easy fix?\n 2) If not, can I back out my change?\n 3) Is git push --dry-run the best way to find out what I changed?  Is there\n    a better way to see what will be pushed?\n 4) Is there a better way to update the timestamps of my commits so that my\n    patches will appear as a solid block of commits in the history (as that\n    is how they will be committed), not interleaved with other changes in\n    the past (giving the false impression that they were applied to the\n    master tree when they were not)?\n\nThanks in advance,\n\nMike\n(:\n\n-- \n--------Mike@PirateHaven.org-----------------------The_glass_is_too_big--------\n"},{"id":"159852","messageId":"201101251732.40811.trast@student.ethz.ch","threadId":"26334","inReplyTo":"20110125114840.GB9367@skull.piratehaven.org","subject":"Re: Confused about git filter-branch results","fromName":"Thomas Rast","fromEmail":"trast@student.ethz.ch","sentAt":"2011-01-25T16:32:40Z","receivedAt":"2011-01-25T16:32:40Z","isPatch":false,"sender":{"key":"tr@thomasrast.ch","avatar":"https://avatars.githubusercontent.com/u/153510?v=4"},"body":"Mike Kelly wrote:\n> filter-branch\n\nBefore you read the explanations below, I recommend that you open\n'gitk --all' and use it to see whether I'm right.\n\n> I was fooling around with 'git filter-branch --env-filter ...' trying to\n> update the timestamps on my commits (which worked), but now when I run\n> 'git whatchanged -p master..' shows all changes to the entire project, not\n> the differences between my branch and the master branch.\n\nMost likely you filtered all commits on your branch, but not master,\nso master now points to an entirely disjoint set of commits.\n\n> Being a novice git user, I'm not sure how much to trust that I didn't hose\n> git in some really weird way, leaving it in a state where it doesn't quite\n> work the way it did before.\n\nIt's hopefully impossible to get git into a *inconsistent* state with\nfilter-branch (i.e., a state that the computer would refuse to\nprocess), but it is indeed quite easy to get it into a state that\nhumans would call \"a mess\".\n\n> The contents of .git/refs/original/refs/heads/ shows a file with my branch\n> name which contains only one entry (presumably the one I updated the\n> timestamp on) so I feel pretty sure that only the commit I wanted to change\n> actually changed.\n\nThat's not how it works.  A branch contains the sha1 of (\"is a pointer\nto\") its tip commit.  The refs/original/refs/heads/foo simply is the\nold value of the branch, i.e., the old tip commit.\n\nYou can use it much like you could use a branch to see the difference\nbetween them, e.g.,\n\n   gitk refs/original/refs/heads/foo...foo\n\nbut note that if the disjoint history theory above holds, this will\nnot be immediately obvious from the output.\n\n> Ultimately, my worry is that I polluted the history which I cloned, and\n> pushing that would make people unhappy.\n\nPushing that would probably make people take a proverbial LART stick\nto your office.\n\nAssuming my \"disjoint history\" theory is correct, you should either\ndiscard your rewrite along the lines of\n\n  git branch -f foo refs/original/refs/heads/foo\n\nand rewrite again with a range limiter, or rebase your rewritten\ncommits.  To illustrate the rebase, assume you had history like\n\n\n   o---o---o---o---o---o  (master)\n                \\\n                 *---*---*  (foo)\n\nIf you really rewrote all history of foo, that means you now have\n\n   o---o---o---B---o---o  (master)\n                \\\n                 1---2---3  (refs/heads/original/foo)\n\n   o'--o'--o'--B'--1'--2'--3'  (foo)\n\nwhere the ' indicates a rewritten copy of the original commit.  You\nneed to manually determine B and B'.  The former will most likely be\n\n  git merge-base master refs/heads/original/foo\n\nThe latter will be its equivalent, so you can take Bs message and\nsearch for its subject in the history of the (rewritten) foo.  Once\nyou know B', you can rebase the commits that were previously on foo\nback to master with\n\n  git rebase --onto B B' foo\n\nThat will create another series of rewritten copies of 1', like so:\n\n   o---o---o---B---o---o  (master)\n               |\\\n               | 1---2---3  (refs/heads/original/foo)\n               |\n                \\\n                 1''--2''--3''  (foo)\n\n   o'--o'--o'--B'--1'--2'--3'  (foo@{1})\n\nConfused yet? :-)\n\n-- \nThomas Rast\ntrast@{inf,student}.ethz.ch\n"},{"id":"159888","messageId":"20110126111835.GA1765@skull.piratehaven.org","threadId":"26334","inReplyTo":"201101251732.40811.trast@student.ethz.ch","subject":"Re: Confused about git filter-branch results","fromName":"Mike Kelly","fromEmail":"mike@piratehaven.org","sentAt":"2011-01-26T11:18:35Z","receivedAt":"2011-01-26T11:18:35Z","isPatch":false,"sender":{"key":"mike@piratehaven.org","avatar":null},"body":"On Tue, Jan 25, 2011 at 05:32:40PM +0100, Thomas Rast wrote:\n> Before you read the explanations below, I recommend that you open\n> 'gitk --all' and use it to see whether I'm right.\n> \nThis was really useful for finding my problem.\n\n> Most likely you filtered all commits on your branch, but not master,\n> so master now points to an entirely disjoint set of commits.\n> \nAlmost exactly correct.  The tree branched off at a really early point in\ndevelopment.\n\n> Assuming my \"disjoint history\" theory is correct, you should either\n> discard your rewrite along the lines of\n> \n>   git branch -f foo refs/original/refs/heads/foo\n> \nDone.  This cleaned up the mess.\n\n> Confused yet? :-)\n> \nNot at all, I found your explanation to be clear and straight forward.\nThank you.\n\nAt first I was grumbling to myself about git filter-branch rewriting every\ncommit, but then I remembered that there were a few messages on stderr\ncomplaining that some commits were not in the correct encoding.  I guess\nthat the tool decided to rewrite these commits for me (without asking),\nthus causing a fork.  Sorry for not mentioning these error messages before,\nI forgot about them in the ensuing panic.\n\nI just want to give a shout-out to all the git developers, I've used RCS,\nCVS, and SVN in the past, and they all had different ways of making life\nmiserable.  Git is the first tool which I felt was working with me, not\nagainst me.  Keep up the good work!\n\nAnyway, I'm back in business and have by branch under control again.\n\nThanks again,\n\nMike\n(:\n\n-- \n--------Mike@PirateHaven.org-----------------------The_glass_is_too_big--------\n"}]}