{"thread":{"id":"26042","subject":"Revert-style merge/Working tree-only checkout?","startedAt":"2010-12-13T23:30:00Z","lastAt":"2010-12-14T19:37:04Z","messageCount":4,"participants":["Yuriy Romanenko","Konstantin Khomoutov","Neal Kreitzinger","Andreas Schwab"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"158010","messageId":"AANLkTi=ioX25aqXg-yWDA0oXBTATkFe+J25g-dB7-psS@mail.gmail.com","threadId":"26042","inReplyTo":null,"subject":"Revert-style merge/Working tree-only checkout?","fromName":"Yuriy Romanenko","fromEmail":"groman@gmail.com","sentAt":"2010-12-13T23:30:00Z","receivedAt":"2010-12-13T23:30:00Z","isPatch":false,"sender":{"key":"groman@gmail.com","avatar":null},"body":"Hello,\n\nI am somewhat new to Git and I keep running into having to accomplish\na certain task and reading through the documentation I can't seem to\nfind any way of doing this easily.\n\nThe problem is when branches diverge and I want to sync a branch to\nanother branch with full overwrite, but maintain history and maintain\nseparate branches.\n\nFor example, say there is a branch \"master\" and I create a branch \"b1\"\nfrom master at some point. After this, there are 5 commits\n(C1,C2,C3,C4,C5) to master and\n17 commits to b1 (let's call them cb1, cb2, cb3, ..., cb17). Say I\nwant to create an 18-th commit to \"b1\" that makes it identical to the\nC5 (current) state of master. Essentially a single commit wipe of\nchanges cb1 -> cb17 as well as application of C1->C5. So far I have\nfound one way of accomplishing this, but it is difficult, error prone,\nslow and I just plain don't like it. I feel like there should be an\neasier way.\n\nWhat I currently do:\n\n$ rm -rf *\n$ git checkout -f master\n$ tar -cvzf /tmp/master.tar.gz *\n$ git checkout b1\n$ rm -rf *\n$ tar -xvzf /tmp/master.tar.gz\n$ git add\n$ git commit -a\n$ git merge master\n\n\nI've considered doing something like the following\n\n$ git checkout b1\n$ git revert b1~17..b1\n$ git merge master\n\nbut it also seems wrong, and requires me to count the submits by hand,\nwhich seems silly --> I'm not actually reverting anything. I don't\nknow if this would even work.\n\n\nAny suggestions on how to accomplish this easier? Some sort of a\nforce-checkout that affects working tree only but not the index?\n\nThank you,\n\nYuriy\n"},{"id":"158032","messageId":"20101214054604.GI3264@localhost.localdomain","threadId":"26042","inReplyTo":"AANLkTi=ioX25aqXg-yWDA0oXBTATkFe+J25g-dB7-psS@mail.gmail.com","subject":"Re: Revert-style merge/Working tree-only checkout?","fromName":"Konstantin Khomoutov","fromEmail":"flatworm@users.sourceforge.net","sentAt":"2010-12-14T05:46:04Z","receivedAt":"2010-12-14T05:46:04Z","isPatch":false,"sender":{"key":"flatworm@users.sourceforge.net","avatar":null},"body":"On Mon, Dec 13, 2010 at 03:30:00PM -0800, Yuriy Romanenko wrote:\n\n> I am somewhat new to Git and I keep running into having to accomplish\n> a certain task and reading through the documentation I can't seem to\n> find any way of doing this easily.\n> \n> The problem is when branches diverge and I want to sync a branch to\n> another branch with full overwrite, but maintain history and maintain\n> separate branches.\n> \n> For example, say there is a branch \"master\" and I create a branch \"b1\"\n> from master at some point. After this, there are 5 commits\n> (C1,C2,C3,C4,C5) to master and\n> 17 commits to b1 (let's call them cb1, cb2, cb3, ..., cb17). Say I\n> want to create an 18-th commit to \"b1\" that makes it identical to the\n> C5 (current) state of master. Essentially a single commit wipe of\n> changes cb1 -> cb17 as well as application of C1->C5. So far I have\n> found one way of accomplishing this, but it is difficult, error prone,\n> slow and I just plain don't like it. I feel like there should be an\n> easier way.\n> \n> What I currently do:\n> \n> $ rm -rf *\n> $ git checkout -f master\n> $ tar -cvzf /tmp/master.tar.gz *\n> $ git checkout b1\n> $ rm -rf *\n> $ tar -xvzf /tmp/master.tar.gz\n> $ git add\n> $ git commit -a\n> $ git merge master\n\nI think this method would work better instead:\n\n    $ git checkout b1\n(2) $ git read-tree --reset master\n(3) $ git checkout-index --all --force\n    $ git commit -m \"Bring b1 to the state of master\"\n(4) $ git merge --no-ff master\n\nIn this sequence, (2) makes the index contain the same state as\nthe tip of the master branch (you can also use more direct name,\nmaster^{tree}, if you like), then (3) throws away any changes appeared\nin the work tree after resetting the index. As the last step, you record\nexplicit merge to indicate that you converged histories back.\n\n> I've considered doing something like the following\n> \n> $ git checkout b1\n> $ git revert b1~17..b1\n> $ git merge master\n> \n> but it also seems wrong, and requires me to count the submits by hand,\nTo not count commits by hand, you could use `git merge-base HEAD master`\nto find the last commit b1 and master shared just before diverging.\n\n> which seems silly --> I'm not actually reverting anything. I don't\n> know if this would even work.\nThis is questionable -- like any VCS, Git was supposedly designed to\ntrack evolving history, and you want to somehow make it track\n\"devolving\" history at times. So, if we would opt not to play powerful\ntricks with Git but rather go a \"normal\" VCS way, you would naturally\nhave to revert your changes to explicitly bring b1 to master.\n"},{"id":"158052","messageId":"ie7veg$ks5$1@dough.gmane.org","threadId":"26042","inReplyTo":"AANLkTi=ioX25aqXg-yWDA0oXBTATkFe+J25g-dB7-psS@mail.gmail.com","subject":"Re: Revert-style merge/Working tree-only checkout?","fromName":"Neal Kreitzinger","fromEmail":"neal@rsss.com","sentAt":"2010-12-14T14:36:20Z","receivedAt":"2010-12-14T14:36:20Z","isPatch":false,"sender":{"key":"neal@rsss.com","avatar":null},"body":"\n\"Yuriy Romanenko\" <groman@gmail.com> wrote in message \nnews:AANLkTi=ioX25aqXg-yWDA0oXBTATkFe+J25g-dB7-psS@mail.gmail.com...\n> Hello,\n>\n> I am somewhat new to Git and I keep running into having to accomplish\n> a certain task and reading through the documentation I can't seem to\n> find any way of doing this easily.\n>\n> The problem is when branches diverge and I want to sync a branch to\n> another branch with full overwrite, but maintain history and maintain\n> separate branches.\n>\n> For example, say there is a branch \"master\" and I create a branch \"b1\"\n> from master at some point. After this, there are 5 commits\n> (C1,C2,C3,C4,C5) to master and\n> 17 commits to b1 (let's call them cb1, cb2, cb3, ..., cb17). Say I\n> want to create an 18-th commit to \"b1\" that makes it identical to the\n> C5 (current) state of master. Essentially a single commit wipe of\n> changes cb1 -> cb17 as well as application of C1->C5. So far I have\n> found one way of accomplishing this, but it is difficult, error prone,\n> slow and I just plain don't like it. I feel like there should be an\n> easier way.\n>\n> What I currently do:\n>\n> $ rm -rf *\n> $ git checkout -f master\n> $ tar -cvzf /tmp/master.tar.gz *\n> $ git checkout b1\n> $ rm -rf *\n> $ tar -xvzf /tmp/master.tar.gz\n> $ git add\n> $ git commit -a\n> $ git merge master\n>\n>\n> I've considered doing something like the following\n>\n> $ git checkout b1\n> $ git revert b1~17..b1\n> $ git merge master\n>\n> but it also seems wrong, and requires me to count the submits by hand,\n> which seems silly --> I'm not actually reverting anything. I don't\n> know if this would even work.\n>\n>\n> Any suggestions on how to accomplish this easier? Some sort of a\n> force-checkout that affects working tree only but not the index?\n>\nHave you looked at the vendor branch methodology in the git-rm manpage?   It \nmay give you some ideas you're interested in.\n\nv/r,\nNeal \n"},{"id":"158085","messageId":"m2zks89me7.fsf@igel.home","threadId":"26042","inReplyTo":"20101214054604.GI3264@localhost.localdomain","subject":"Re: Revert-style merge/Working tree-only checkout?","fromName":"Andreas Schwab","fromEmail":"schwab@linux-m68k.org","sentAt":"2010-12-14T19:37:04Z","receivedAt":"2010-12-14T19:37:04Z","isPatch":false,"sender":{"key":"schwab@linux-m68k.org","avatar":"https://avatars.githubusercontent.com/u/2175493?v=4"},"body":"Konstantin Khomoutov <flatworm@users.sourceforge.net> writes:\n\n> (2) $ git read-tree --reset master\n> (3) $ git checkout-index --all --force\n\n$ git rm -r .\n$ git checkout master .\n\nAndreas.\n\n-- \nAndreas Schwab, schwab@linux-m68k.org\nGPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5\n\"And now for something completely different.\"\n"}]}