{"thread":{"id":"47441","subject":"Need help migrating workflow from svn to git.","startedAt":"2017-12-14T13:28:20Z","lastAt":"2017-12-21T22:04:22Z","messageCount":16,"participants":["Josef Wolf","Randall S. Becker","Igor Djordjevic","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"334804","messageId":"20171214130933.GA18542@raven.inka.de","threadId":"47441","inReplyTo":null,"subject":"Need help migrating workflow from svn to git.","fromName":"Josef Wolf","fromEmail":"jw@raven.inka.de","sentAt":"2017-12-14T13:09:33Z","receivedAt":"2017-12-14T13:28:20Z","isPatch":false,"sender":{"key":"jw@raven.inka.de","avatar":null},"body":"Hello folks,\n\nI am wondering whether/how my mode of work for a specific project\n(currently based on SVN) could be transferred to git.\n\nI have a repository for maintaining configuration of hosts. This repository\ncontains several hundered scripts. Most of those scripts are don't depend on\neach other.\n\nEvery machine has a working copy of the repository in a specific\ndirectory. A cron job (running every 15 minutes) executes \"svn update\" and\nexecutes the scripts which are contained in this working copy.\n\nThis way, I can commit changes to the main repository and all the hosts\nwill \"download\" and adopt by executing the newest revision of those\nscripts. (The scripts need to be idempotent, but this is a different\ntopic).\n\nNORMALLY, there are no local modifications in the working copy. Thus,\nconflicts can not happen. Everything works fine.\n\nSometimes, I need to fix a problem on some host or need to implement a new\nfeature. For this, I go to the working copy of a host where the change\nneeds to be done and start haking. With svn, I don't need to stop the cron\njob. \"svn update\" will happily merge any in-coming changes and leave alone\nthe files which were not modified upstream. Conflicts with my local\nmodifications which I am currently hacking on are extremely rare, because\nthe scripts are pretty much independent. So I'm pretty much happy with this\nmode of operation.\n\nWith git, by contrast, this won't work. Git will refuse to pull anything as\nlong as there are ANY local modifications. The cron job would need to\n\n   git stash\n   git pull\n   git stash pop\n\nBut this will temporarily remove my local modifications. If I happen to do\na test run at this time, the test run would NOT contain the local\nmodifications which I was about to test. Even worse: if I happen to save\none of the modified files while the modifications are in the stash, the\n\"git stash pop\" will definitely cause a conflict, although nothing really\nchanged.\n\nSo, how would I get this workflow with git? Is it possible to emulate the\nbehavior of \"svn update\"?\n\nAny ideas?\n\n-- \nJosef Wolf\njw@raven.inka.de\n"},{"id":"334835","messageId":"005801d3751f$859f6c50$90de44f0$@nexbridge.com","threadId":"47441","inReplyTo":"20171214130933.GA18542@raven.inka.de","subject":"RE: Need help migrating workflow from svn to git.","fromName":"Randall S. Becker","fromEmail":"rsbecker@nexbridge.com","sentAt":"2017-12-14T21:07:15Z","receivedAt":"2017-12-14T21:07:38Z","isPatch":false,"sender":{"key":"randall.becker@nexbridge.ca","avatar":"https://avatars.githubusercontent.com/u/28956764?v=4"},"body":"> On December 14, 2017 8:10 AM, Josef Wolf wrote:\n> Subject: Need help migrating workflow from svn to git.\n> \n> Hello folks,\n> \n> I am wondering whether/how my mode of work for a specific project\n> (currently based on SVN) could be transferred to git.\n> \n> I have a repository for maintaining configuration of hosts. This\nrepository\n> contains several hundered scripts. Most of those scripts are don't depend\non\n> each other.\n> \n> Every machine has a working copy of the repository in a specific\ndirectory. A\n> cron job (running every 15 minutes) executes \"svn update\" and executes the\n> scripts which are contained in this working copy.\n> \n> This way, I can commit changes to the main repository and all the hosts\nwill\n> \"download\" and adopt by executing the newest revision of those scripts.\n> (The sripts need to be idempotent, but this is a different topic).\n> \n> NORMALLY, there are no local modifications in the working copy. Thus,\n> conflicts can not happen. Everything works fine.\n> \n> Sometimes, I need to fix a problem on some host or need to implement a\n> new feature. For this, I go to the working copy of a host where the change\n> needs to be done and start haking. With svn, I don't need to stop the cron\n> job. \"svn update\" will happily merge any in-coming changes and leave alone\n> the files which were not modified upstream. Conflicts with my local\n> modifications which I am currently hacking on are extremely rare, because\n> the scripts are pretty much independent. So I'm pretty much happy with\nthis\n> mode of operation.\n> \n> With git, by contrast, this won't work. Git will refuse to pull anything\nas long\n> as there are ANY local modifications. The cron job would need to\n> \n>    git stash\n>    git pull\n>    git stash pop\n> \n> But this will temporarily remove my local modifications. If I happen to do\na\n> test run at this time, the test run would NOT contain the local\nmodifications\n> which I was about to test. Even worse: if I happen to save one of the\n> modified files while the modifications are in the stash, the \"git stash\npop\" will\n> definitely cause a conflict, although nothing really changed.\n> \n> So, how would I get this workflow with git? Is it possible to emulate the\n> behavior of \"svn update\"?\n> \n> Any ideas?\n\nYou might want to consider a slight modification to your approach as\nfollows. \nInstead of using git pull, use git fetch.\nHave each system on its own branch (sys1 = my-sys1-branch, for example) so\nyou can track who has what.\nIn your scripts, consider:\ngit fetch\nif nothing changed, done\ngit status\nif no changes, git merge --ff  master && git push origin my-sys1-branch &&\ndone\nif changes, send an email whining about the changes\nyour script could then (depending on your environment) git commit -a && git\nmerge && git push origin my-sys1-branch && done\n\nThis would allow you to track the condition of each system at your single\nupstream repository. \n\nJust my $0.02\n\nCheers.\nRandall\\\n-- Brief whoami: NonStop&UNIX developer since approximately\nUNIX(421664400)/NonStop(211288444200000000)\n-- In my real life, I talk too much.\n\n\n\n"},{"id":"334853","messageId":"5eb3fe18-864d-0b04-223e-d9e5cbf2c81e@gmail.com","threadId":"47441","inReplyTo":"20171214130933.GA18542@raven.inka.de","subject":"Re: Need help migrating workflow from svn to git.","fromName":"Igor Djordjevic","fromEmail":"igor.d.djordjevic@gmail.com","sentAt":"2017-12-14T22:27:09Z","receivedAt":"2017-12-14T22:27:20Z","isPatch":false,"sender":{"key":"igor.d.djordjevic@gmail.com","avatar":null},"body":"Hi Josef,\n\nI`m not a Git expert, and I know less of Subversion, but following \nyour explanation, I might try to help, at least until more \nexperienced people join.\n\nOn 14/12/2017 14:09, Josef Wolf wrote:\n> \n> Every machine has a working copy of the repository in a specific \n> directory. A cron job (running every 15 minutes) executes \"svn\n> update\" and executes the scripts which are contained in this working\n> copy.\n> ...\n> Sometimes, I need to fix a problem on some host or need to implement\n> a new feature. For this, I go to the working copy of a host where the\n> change needs to be done and start haking. With svn, I don't need to\n> stop the cron job. \"svn update\" will happily merge any in-coming\n> changes and leave alone the files which were not modified upstream.\n> Conflicts with my local modifications which I am currently hacking on\n> are extremely rare, because the scripts are pretty much independent.\n> So I'm pretty much happy with this mode of operation.\n\nAside \"update and merge\" working copy while you`re hacking on it, \nwhat happens with \"execute\" part? It seems really strange that you \ndon`t mind cron job running the same scripts which you are actively \nworking on, thus being in an inconsistent state, if not broken, even.\n\n> With git, by contrast, this won't work. Git will refuse to pull\n> anything as long as there are ANY local modifications.\n\nNot sure what`s happening at your end, but \"ANY\" part shouldn`t be \ntrue - you can have local modifications and still execute `git pull` \nsuccessfully.\n\nOnly if you have local modifications in files that _also_ changed on \nthe remote end, `git pull` aborts (fetch of the remote branch \nsucceeds, actually, just merge with local branch is aborted).\n\nNow, having in mind you said conflicts are extremely rare in your \nflow anyway, would this be enough for you? Of course, provided that \nissue you`re having with being unable to `git pull` with ANY local \nmodifications, as you wrote, is resolved first.\n\n> The cron job would need to\n> \n>    git stash\n>    git pull\n>    git stash pop\n> \n> But this will temporarily remove my local modifications. If I happen\n> to do a test run at this time, the test run would NOT contain the\n> local modifications which I was about to test. Even worse: if I\n> happen to save one of the modified files while the modifications are\n> in the stash, the \"git stash pop\" will definitely cause a conflict,\n> although nothing really changed.\n\nIs `git stash pop` causing conflicts your only concern here? How \nabout a situation where you save one of the modified files _after_ \n`git stash pop` was successful, effectively discarding any updates \nintroduced by `git pull` from remote end...?\n\nAs you basically have a flow where two users (you and cron job) can \nedit same files at the same time, desired outcome might be a bit \nambiguous, especially when scheduled execution of those files is \nadded to the mix.\n\n> So, how would I get this workflow with git? Is it possible to emulate\n> the behavior of \"svn update\"?\n> \n> Any ideas?\n\nI`m thinking of a workflow involving (scripted) creation of a \ntemporary branch at fetched remote branch position, and using \nsomething like `git checkout --merge <temp_branch>` to merge your \nlocal modifications to latest changes fetched from remote (ending up \nwith conflicts inside working tree, if any), which would seem to \nsimulate `svn update` as desired (if I understand it correctly), but \nit might be good to address some of the concerns I raised above first.\n\nRegards, Buga\n"},{"id":"334866","messageId":"b25a828f-3f0a-7c0e-6722-9521238ce7f3@gmail.com","threadId":"47441","inReplyTo":"5eb3fe18-864d-0b04-223e-d9e5cbf2c81e@gmail.com","subject":"Re: Need help migrating workflow from svn to git.","fromName":"Igor Djordjevic","fromEmail":"igor.d.djordjevic@gmail.com","sentAt":"2017-12-15T01:17:40Z","receivedAt":"2017-12-15T01:18:14Z","isPatch":false,"sender":{"key":"igor.d.djordjevic@gmail.com","avatar":null},"body":"On 14/12/2017 23:27, Igor Djordjevic wrote:\n> \n> As you basically have a flow where two users (you and cron job) can \n> edit same files at the same time, desired outcome might be a bit \n> ambiguous, especially when scheduled execution of those files is \n> added to the mix.\n\nThis said, and without having you to change your habits too much (nor \nuse Git in possibly awkward ways), I`m thinking you may actually \nbenefit of using `git worktree add <temp_copy_path>`[1] to create a \ntemporary working tree (\"working copy\", as you say), alongside a \ntemporary branch, where you could hack and test as much as you want, \nunaffected by cron job updating and executing the original working \ncopy/branch (also not stepping on cron job`s toes yourself).\n\nOnce you`re satisfied and you commit/merge/push your changes from \nwithin the temporary working copy/branch, you can just delete it \n(both temporary working copy and its branch), and you`re good :)\n\np.s. Even if you`re not familiar with Git branching and merging, it \nshouldn`t take too much effort to wrap your head around it, and it`s \ndefinitely worth it - and actually pretty easy, even more if you`re \nworking alone.\n\n[1] https://git-scm.com/docs/git-worktree\n"},{"id":"334872","messageId":"20171215102759.GB18542@raven.inka.de","threadId":"47441","inReplyTo":"005801d3751f$859f6c50$90de44f0$@nexbridge.com","subject":"Re: Need help migrating workflow from svn to git.","fromName":"Josef Wolf","fromEmail":"jw@raven.inka.de","sentAt":"2017-12-15T10:27:59Z","receivedAt":"2017-12-15T10:30:19Z","isPatch":false,"sender":{"key":"jw@raven.inka.de","avatar":null},"body":"Thanks for your answer, Randall,\n\nOn Thu, Dec 14, 2017 at 04:07:15PM -0500, Randall S. Becker wrote:\n> \n> You might want to consider a slight modification to your approach as\n> follows. \n> Instead of using git pull, use git fetch.\n> Have each system on its own branch (sys1 = my-sys1-branch, for example) so\n> you can track who has what.\n> In your scripts, consider:\n> git fetch\n> if nothing changed, done\n> git status\n> if no changes, git merge --ff  master && git push origin my-sys1-branch &&\n> done\n> if changes, send an email whining about the changes\n> your script could then (depending on your environment) git commit -a && git\n> merge && git push origin my-sys1-branch && done\n\nThe scripts never commit. In fact, they only have read access to the remote\nrepository. Commits are only ever done by humans manually.\n\nSo it's going to be something like this:\n\n  git fetch origin\n  if [ git diff -s master origin/master ]\n    git stash\n    git merge -ff master\n    git stash pop\n  fi\n\nUnfortunately, the return code of git-diff don't seem to indicate whether they\nhave diverged. And git-status don't seem to have an option to specify \"remote\nis ahead of me\". How would I properly check whether a merge is actually needed?\n\n-- \nJosef Wolf\njw@raven.inka.de\n"},{"id":"334877","messageId":"20171215124739.GC18542@raven.inka.de","threadId":"47441","inReplyTo":"5eb3fe18-864d-0b04-223e-d9e5cbf2c81e@gmail.com","subject":"Re: Need help migrating workflow from svn to git.","fromName":"Josef Wolf","fromEmail":"jw@raven.inka.de","sentAt":"2017-12-15T12:47:39Z","receivedAt":"2017-12-15T12:50:22Z","isPatch":false,"sender":{"key":"jw@raven.inka.de","avatar":null},"body":"Thanks for your input, Igor!\n\nOn Thu, Dec 14, 2017 at 11:27:09PM +0100, Igor Djordjevic wrote:\n> Aside \"update and merge\" working copy while you`re hacking on it, \n> what happens with \"execute\" part? It seems really strange that you \n> don`t mind cron job running the same scripts which you are actively \n> working on, thus being in an inconsistent state, if not broken, even.\n\nIn theory, you're right. In practice, problems are almost non-existent because\nof:\n\n1. Scripts are independant from each other. Would there be a problem with one\n   script, the other several hundred scripts will still continue to work.\n2. Most changes to existing scripts are just minor tweaks. Not much room to\n   wind up.\n3. When new scripts/features are introduced, it is usually to some aspect that\n   were non-existing before. Breaking something that did not work before is\n   not a big issue.\n4. Even IF cron happens to execute something half-baked, most of the time it\n   will give a syntax error. The effect is as if the cron job would have been\n   stopped entirely\n5. When there's a major refactoring to be done where some problems are to\n   expected, then the cron entry is disabled.\n\nSo, in practice, it's pretty much a non-issue.\n\n> > With git, by contrast, this won't work. Git will refuse to pull\n> > anything as long as there are ANY local modifications.\n> \n> Not sure what`s happening at your end, but \"ANY\" part shouldn`t be \n> true - you can have local modifications and still execute `git pull` \n> successfully.\n> \n> Only if you have local modifications in files that _also_ changed on \n> the remote end, `git pull` aborts (fetch of the remote branch \n> succeeds, actually, just merge with local branch is aborted).\n\nOh, you're right! I don't know where I catched the idea that ANY modification\nwould stop \"git pull\" from working...\n\n> Now, having in mind you said conflicts are extremely rare in your \n> flow anyway, would this be enough for you?\n\nNo. There's still the issue with \"git pop\", even if no modifications are\ncoming from upstream.\n\n> > The cron job would need to\n> > \n> >    git stash\n> >    git pull\n> >    git stash pop\n> > \n> > But this will temporarily remove my local modifications. If I happen\n> > to do a test run at this time, the test run would NOT contain the\n> > local modifications which I was about to test. Even worse: if I\n> > happen to save one of the modified files while the modifications are\n> > in the stash, the \"git stash pop\" will definitely cause a conflict,\n> > although nothing really changed.\n> \n> Is `git stash pop` causing conflicts your only concern here? How \n> about a situation where you save one of the modified files _after_ \n> `git stash pop` was successful, effectively discarding any updates \n> introduced by `git pull` from remote end...?\n\nIt's both. With the conflict having the highest probability.\n\n> As you basically have a flow where two users (you and cron job) can \n> edit same files at the same time, desired outcome might be a bit \n> ambiguous, especially when scheduled execution of those files is \n> added to the mix.\n\nYeah. That's the difference with svn: Svn won't touch the files unless there\nare changes coming from upstream. In contrast, git-stash WILL touch ALL\nlocally modified files, even the files which were not touched at all upstream.\n\nSo with svn, only files are at risk which are locally modified AND which have\nbeen changed upstream. With git-stash, EVERY locally modified file is at risk.\n\n> I`m thinking of a workflow involving (scripted) creation of a \n> temporary branch at fetched remote branch position, and using \n> something like `git checkout --merge <temp_branch>` to merge your \n> local modifications to latest changes fetched from remote (ending up \n> with conflicts inside working tree, if any),\n\nBut this would require local modifications to be committed?\n\n-- \nJosef Wolf\njw@raven.inka.de\n"},{"id":"334879","messageId":"20171215130645.GD18542@raven.inka.de","threadId":"47441","inReplyTo":"b25a828f-3f0a-7c0e-6722-9521238ce7f3@gmail.com","subject":"Re: Need help migrating workflow from svn to git.","fromName":"Josef Wolf","fromEmail":"jw@raven.inka.de","sentAt":"2017-12-15T13:06:45Z","receivedAt":"2017-12-15T13:10:17Z","isPatch":false,"sender":{"key":"jw@raven.inka.de","avatar":null},"body":"On Fri, Dec 15, 2017 at 02:17:40AM +0100, Igor Djordjevic wrote:\n> \n> This said, and without having you to change your habits too much (nor \n> use Git in possibly awkward ways), I`m thinking you may actually \n> benefit of using `git worktree add <temp_copy_path>`[1] to create a \n> temporary working tree (\"working copy\", as you say), alongside a \n> temporary branch, where you could hack and test as much as you want, \n> unaffected by cron job updating and executing the original working \n> copy/branch (also not stepping on cron job`s toes yourself).\n\nInteresting command. Did not know about it. Will remembre it for other use\ncases!\n\nBut in this case, it is not of much use. See, I am doing system configuration\nwith those scripts. Having two working trees would cause the configuration to\nbe restored every time cron happens to start the scripts.\n\nDoing the modifications right there where cron executes has the benefit that\ncron uses the same modifications which I am using. This way, whenever cron\ndecides to execute, it is exactly the same as if I would do a \"make run\" on\nthe command line. Since all the scripts are designed to be idempotent,\neverything works pretty much flawlessly.\n\n-- \nJosef Wolf\njw@raven.inka.de\n"},{"id":"334892","messageId":"xmqqvah8q7cg.fsf@gitster.mtv.corp.google.com","threadId":"47441","inReplyTo":"20171214130933.GA18542@raven.inka.de","subject":"Re: Need help migrating workflow from svn to git.","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2017-12-15T16:33:19Z","receivedAt":"2017-12-15T16:33:30Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Josef Wolf <jw@raven.inka.de> writes:\n\n> With git, by contrast, this won't work. Git will refuse to pull anything as\n> long as there are ANY local modifications. The cron job would need to\n>\n>    git stash\n>    git pull\n>    git stash pop\n\nI'd assume that this \"pull\" is expected to be fast-forward, as\notherwise you have no way of dealing with conflicted merges.\n\n> But this will temporarily remove my local modifications. If I happen to do\n> a test run at this time, the test run would NOT contain the local\n> modifications which I was about to test. Even worse: if I happen to save\n> one of the modified files while the modifications are in the stash, the\n> \"git stash pop\" will definitely cause a conflict, although nothing really\n> changed.\n>\n> So, how would I get this workflow with git? Is it possible to emulate the\n> behavior of \"svn update\"?\n\nYou do not mind a temporary inconsistency while \"svn update\" runs\n(it starts to update a file you may have local changes, but your\ntest may run while the update is in the middle of it).  So perhaps\nsomething along the lines of this would help.  Assuming\n\n    <remote> <branch>: the branch at the remote you are pulling from\n    <master>: whatever branch you are using\n\nare in your three-command example above:\n\n    $ git fetch <remote> <branch>\n    $ git checkout -m -B <master> FETCH_HEAD\n\nshould give you pretty-much identical result as\n\n    $ git stash && git pull --ff-only && git stash pop\n\nincluding a possible merge conflicts at 'git stash pop' stage.\n"},{"id":"334898","messageId":"0c0867d8-73d7-3577-be26-2a9a7691d58b@gmail.com","threadId":"47441","inReplyTo":"20171215124739.GC18542@raven.inka.de","subject":"Re: Need help migrating workflow from svn to git.","fromName":"Igor Djordjevic","fromEmail":"igor.d.djordjevic@gmail.com","sentAt":"2017-12-15T18:24:03Z","receivedAt":"2017-12-15T18:24:32Z","isPatch":false,"sender":{"key":"igor.d.djordjevic@gmail.com","avatar":null},"body":"Hi Josef,\n\nThank you for your patient answers. From what you said here and in \nthat other reply[1], it looks like you know what you`re doing, you`re \naware of circumstances, and you still prefer doing it that way.\n\nSo, here it goes... :)\n\nOn 15/12/2017 13:47, Josef Wolf wrote:\n> \n> > I`m thinking of a workflow involving (scripted) creation of a \n> > temporary branch at fetched remote branch position, and using \n> > something like `git checkout --merge <temp_branch>` to merge your \n> > local modifications to latest changes fetched from remote (ending\n> > up with conflicts inside working tree, if any),\n> \n> But this would require local modifications to be committed?\n \nNope :) Here`s a script you can test to see if it works for you, \nsimulating `svn update` (at least how I perceived it).\n\nFeel free to adapt as you feel like it (I used local \"master\" branch \nand remote \"origin/master\", for example), or to speak up if any \nadditional info is needed.\n\n    git checkout -b temp &&               #1\n    git fetch &&                          #2\n    git branch -f master origin/master && #3\n    git checkout -m master &&             #4\n    git add -u &&                         #5\n    git reset &&                          #6\n    git branch -d temp                    #7\n\nExplanation:\n 1. Create temporary branch where we are, switching to it, so we can \n    update \"master\" without local modifications\n 2. Fetch latest updates\n 3. Update \"master\" to fetched \"origin/master\"\n 4. Switch to updated \"master\", merging local modifications\n 5. Mark any pending merge conflicts as resolved by staging them...\n 6. ... and unstage them right away\n 7. Delete temporary branch\n\nStep (4) is what merges your local modifications with remote updates \n(leaving conflicts, if any), where steps (5) and (6) are not needed \nfor a single run, but in case you don`t resolve conflicts before next \ncron job executes this script again, step (1) will now fail without \nthem because of (still) unresolved merge conflicts.\n\nSo, as you seem to be pretty at ease with your flow, you might prefer \nleaving those two steps (5, 6) in.\n\nThis does seem ugly and hacky, but if it works for you, I don`t judge :) \nPlease note that there might be better ways to accomplish this, I \nrepeat, I`m not an expert, but hopefully this could do the job.\n\nAlso, if I missed something, I hope someone will correct me.\n\nRegards, Buga\n\n[1] https://public-inbox.org/git/20171215130645.GD18542@raven.inka.de/\n"},{"id":"334900","messageId":"19d67f01-5e7d-3792-52f4-52da86bca5e5@gmail.com","threadId":"47441","inReplyTo":"xmqqvah8q7cg.fsf@gitster.mtv.corp.google.com","subject":"Re: Need help migrating workflow from svn to git.","fromName":"Igor Djordjevic","fromEmail":"igor.d.djordjevic@gmail.com","sentAt":"2017-12-15T18:58:14Z","receivedAt":"2017-12-15T18:58:23Z","isPatch":false,"sender":{"key":"igor.d.djordjevic@gmail.com","avatar":null},"body":"On 15/12/2017 17:33, Junio C Hamano wrote:\n> \n>     $ git fetch <remote> <branch>\n>     $ git checkout -m -B <master> FETCH_HEAD\n\n... aaand that`s how you do it[1] without a temporary branch :)\n\nJunio, what about consecutive runs, while merge conflicts are still \nunresolved?\n\nSeeing Josef having a pretty relaxed flow, and his cron job running \nevery 15 minutes, would adding something like:\n\n    $ git add -u\n    $ git reset\n\n... to the mix, to \"silence\" actually still unresolved merge \nconflicts, making next script execution possible, make sense?\n\nYes, `git diff` won`t be the same as if conflicts were still in, but \nit might be worth it in this specific case, conflicting parts still \neasily visible between conflict markers.\n\nRegards, Buga\n\n[1] On 15/12/2017 19:24, Igor Djordjevic wrote:\n> \n>     git checkout -b temp &&               #1\n>     git fetch &&                          #2\n>     git branch -f master origin/master && #3\n>     git checkout -m master &&             #4\n>     git add -u &&                         #5\n>     git reset &&                          #6\n>     git branch -d temp                    #7\n> \n> Explanation:\n>  1. Create temporary branch where we are, switching to it, so we can \n>     update \"master\" without local modifications\n>  2. Fetch latest updates\n>  3. Update \"master\" to fetched \"origin/master\"\n>  4. Switch to updated \"master\", merging local modifications\n>  5. Mark any pending merge conflicts as resolved by staging them...\n>  6. ... and unstage them right away\n>  7. Delete temporary branch\n> \n> Step (4) is what merges your local modifications with remote updates \n> (leaving conflicts, if any), where steps (5) and (6) are not needed \n> for a single run, but in case you don`t resolve conflicts before next \n> cron job executes this script again, step (1) will now fail without \n> them because of (still) unresolved merge conflicts.\n> \n> So, as you seem to be pretty at ease with your flow, you might prefer \n> leaving those two steps (5, 6) in.\n"},{"id":"334901","messageId":"xmqq1sjvreoy.fsf@gitster.mtv.corp.google.com","threadId":"47441","inReplyTo":"19d67f01-5e7d-3792-52f4-52da86bca5e5@gmail.com","subject":"Re: Need help migrating workflow from svn to git.","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2017-12-15T19:09:17Z","receivedAt":"2017-12-15T19:09:24Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Igor Djordjevic <igor.d.djordjevic@gmail.com> writes:\n\n> Junio, what about consecutive runs, while merge conflicts are still \n> unresolved?\n\nThe impression I got was that the original running with svn does not\ndeal with conflicting situation anyway, so I did not think about it\nat all, and I personally do not care ;-)\n"},{"id":"334903","messageId":"89694b65-a0b0-c505-fcab-24c2e8961b12@gmail.com","threadId":"47441","inReplyTo":"xmqq1sjvreoy.fsf@gitster.mtv.corp.google.com","subject":"Re: Need help migrating workflow from svn to git.","fromName":"Igor Djordjevic","fromEmail":"igor.d.djordjevic@gmail.com","sentAt":"2017-12-15T19:20:15Z","receivedAt":"2017-12-15T19:20:24Z","isPatch":false,"sender":{"key":"igor.d.djordjevic@gmail.com","avatar":null},"body":"On 15/12/2017 20:09, Junio C Hamano wrote:\n> \n> > Junio, what about consecutive runs, while merge conflicts are still \n> > unresolved?\n> \n> The impression I got was that the original running with svn does not\n> deal with conflicting situation anyway, so I did not think about it\n> at all, and I personally do not care ;-)\n\nHeh, fair enough :) Though I was genuinely interested if there is a \nbetter way to accomplish it than `git add -u && git reset`, but I \nguess I can take that as \"whatever works\" ;)\n"},{"id":"335069","messageId":"20171220114337.GE18542@raven.inka.de","threadId":"47441","inReplyTo":"19d67f01-5e7d-3792-52f4-52da86bca5e5@gmail.com","subject":"Re: Need help migrating workflow from svn to git.","fromName":"Josef Wolf","fromEmail":"jw@raven.inka.de","sentAt":"2017-12-20T11:43:37Z","receivedAt":"2017-12-20T11:50:15Z","isPatch":false,"sender":{"key":"jw@raven.inka.de","avatar":null},"body":"Thanks to you both for your patience with me. Sorry for the late reply, my day\njob was needing me ;-)\n\nOn Fri, Dec 15, 2017 at 07:58:14PM +0100, Igor Djordjevic wrote:\n> On 15/12/2017 17:33, Junio C Hamano wrote:\n> > \n> >     $ git fetch <remote> <branch>\n> >     $ git checkout -m -B <master> FETCH_HEAD\n\nFor some reason, this seems to double the local modifications. After executing\nthe following commands:\n\n\n  rm -rf reposA reposB\n  \n  git init reposA\n  (\n    cd reposA\n    echo 1 >>1\n    echo 2 >>2\n    git add 1 2\n    git commit -m1\n  )\n  \n  git clone reposA reposB\n  \n  (\n    cd reposA\n    echo 1 >>1\n    git commit -a -m2\n  )\n  \n  (\n    cd reposB\n    echo 3 >>2\n    git fetch\n    git checkout -m -B master FETCH_HEAD\n  )\n\ngit-diff gives me:\n\n  $ diff --git a/2 b/2\n  index 0cfbf08..4e8a2de 100644\n  --- a/2\n  +++ b/2\n  @@ -1 +1,3 @@\n   2\n  +3\n  +3\n\nWith Igor's set of commands, I did not see this doubling:\n\n>     git checkout -b temp &&               #1\n>     git fetch &&                          #2\n>     git branch -f master origin/master && #3\n>     git checkout -m master &&             #4\n>     git add -u &&                         #5\n>     git reset &&                          #6\n>     git branch -d temp                    #7\n\n> ... aaand that`s how you do it[1] without a temporary branch :)\n> \n> Junio, what about consecutive runs, while merge conflicts are still \n> unresolved?\n> \n> Seeing Josef having a pretty relaxed flow, and his cron job running \n> every 15 minutes, would adding something like:\n> \n>     $ git add -u\n>     $ git reset\n\nThis would be added after the \"git checkout -m -B master FETCH_HEAD\" command?\n\n> ... to the mix, to \"silence\" actually still unresolved merge \n> conflicts, making next script execution possible, make sense?\n> \n> Yes, `git diff` won`t be the same as if conflicts were still in, but \n> it might be worth it in this specific case, conflicting parts still \n> easily visible between conflict markers.\n\nThat means, the conflict is still there, but git would think this is an\nordinary modification?\n\n-- \nJosef Wolf\njw@raven.inka.de\n"},{"id":"335072","messageId":"20171220115213.GF18542@raven.inka.de","threadId":"47441","inReplyTo":"xmqq1sjvreoy.fsf@gitster.mtv.corp.google.com","subject":"Re: Need help migrating workflow from svn to git.","fromName":"Josef Wolf","fromEmail":"jw@raven.inka.de","sentAt":"2017-12-20T11:52:13Z","receivedAt":"2017-12-20T12:00:16Z","isPatch":false,"sender":{"key":"jw@raven.inka.de","avatar":null},"body":"On Fri, Dec 15, 2017 at 11:09:17AM -0800, Junio C Hamano wrote:\n> Igor Djordjevic <igor.d.djordjevic@gmail.com> writes:\n> \n> > Junio, what about consecutive runs, while merge conflicts are still \n> > unresolved?\n> \n> The impression I got was that the original running with svn does not\n> deal with conflicting situation anyway, so I did not think about it\n> at all, and I personally do not care ;-)\n\nYeah. Conflicts are not a big deal for this project.\n\nI guess, this would no longer hold true if there are lots of developers with\nlots of commits. Thus, I'd still like to learn how to do it correctly.\n\nNever doing local modifications in the \"live\" directories would require to\ninstall test systems and simulate their environment just for doing some minor\nadjustments.\n\n-- \nJosef Wolf\njw@raven.inka.de\n"},{"id":"335073","messageId":"20171220121939.GG18542@raven.inka.de","threadId":"47441","inReplyTo":"20171220114337.GE18542@raven.inka.de","subject":"Re: Need help migrating workflow from svn to git.","fromName":"Josef Wolf","fromEmail":"jw@raven.inka.de","sentAt":"2017-12-20T12:19:39Z","receivedAt":"2017-12-20T12:20:18Z","isPatch":false,"sender":{"key":"jw@raven.inka.de","avatar":null},"body":"On Wed, Dec 20, 2017 at 12:43:37PM +0100, Josef Wolf wrote:\n> Thanks to you both for your patience with me. Sorry for the late reply, my day\n> job was needing me ;-)\n> \n> On Fri, Dec 15, 2017 at 07:58:14PM +0100, Igor Djordjevic wrote:\n> > On 15/12/2017 17:33, Junio C Hamano wrote:\n> > > \n> > >     $ git fetch <remote> <branch>\n> > >     $ git checkout -m -B <master> FETCH_HEAD\n> \n> For some reason, this seems to double the local modifications. After executing\n> the following commands:\n\nUmm... Please ignore this \"doubling\" comment. My test script was faulty :-//\n\nSorry for the confusion!\n\n-- \nJosef Wolf\njw@raven.inka.de\n"},{"id":"335156","messageId":"fdf75150-eca0-dde5-a305-ae5fd5c35369@gmail.com","threadId":"47441","inReplyTo":"20171220114337.GE18542@raven.inka.de","subject":"Re: Need help migrating workflow from svn to git.","fromName":"Igor Djordjevic","fromEmail":"igor.d.djordjevic@gmail.com","sentAt":"2017-12-21T22:04:09Z","receivedAt":"2017-12-21T22:04:22Z","isPatch":false,"sender":{"key":"igor.d.djordjevic@gmail.com","avatar":null},"body":"Hi Josef,\n\nOn 20/12/2017 12:43, Josef Wolf wrote:\n> \n>>     $ git add -u\n>>     $ git reset\n> \n> This would be added after the \"git checkout -m -B master FETCH_HEAD\" \n> command?\n\nYes, so it would be something like this:\n\n    git fetch origin master &&              #1\n    git checkout -m -B master FETCH_HEAD && #2\n    git add -u &&                           #3\n    git reset                               #4\n\nBut it actually depends on what kind of default `git diff` output \nyou prefer.\n\nIn order to avoid failure on subsequent script runs, in case where \nconflicts still exist, you need to ensure #3 and #4 are executed \nbefore #1 and #2 are executed _again_.\n\nSo you may put #3 and #4 in front of #1 and #2, too, that would work \njust as well, where `git diff` would now be showing \"combined diff\"[2] \nas long as the script isn`t executed again (and it would keep showing \nnew \"combined diff\" from that point on).\n\n>> Yes, `git diff` won`t be the same as if conflicts were still in, but \n>> it might be worth it in this specific case, conflicting parts still \n>> easily visible between conflict markers.\n> \n> That means, the conflict is still there, but git would think this is \n> an ordinary modification?\n\nYes, as by that `git add -u` you confirm all merge conflicts are \nresolved, and `git diff` output changes accordingly. You can read \nmore about \"diff format for merges\"[1] and \"combined diff format\"[2] \nfrom `git-diff`[3] documentation.\n\nHere are some examples from my test repositories. Local repo \nintroduces line \"A1\" (local modification, uncommitted), where remote \nrepo introduced line \"B1\" (commit). Steps #1 and #2 get executed, merge \nconflicts shown with `git diff`, before `git add -u` and `git reset`:\n\n    $ git diff\n    diff --cc A\n    index 5314b4f,1e2b966..0000000\n    --- a/A\n    +++ b/A\n    @@@ -12,5 -12,5 +12,9 @@@\n      2\n      3\n      4\n    ++<<<<<<< FETCH_HEAD\n     +B1\n    ++=======\n    + A1\n    ++>>>>>>> local\n      5\n\n... and after `git add -u` and `git reset` (note line \"B1\" not \nshowing as changed anymore):\n\n    $ git diff\n    diff --git a/A b/A\n    index 5314b4f..8ea9600 100644\n    --- a/A\n    +++ b/A\n    @@ -12,5 +12,9 @@ A\n     2\n     3\n     4\n    +<<<<<<< FETCH_HEAD\n     B1\n    +=======\n    +A1\n    +>>>>>>> local\n     5\n\n\nNow, without any commits yet made locally (except commit pulled from \nremote repo), local repo adds line \"A2\" where remote repo introduces \nline \"B2\" (commit). Steps #1 and #2 get executed again, merge \nconflicts shown with `git diff`, before `git add -u` and `git reset`:\n\n    $ git diff\n    diff --cc A\n    index 424ae9e,4aac880..0000000\n    --- a/A\n    +++ b/A\n    @@@ -2,7 -2,7 +2,11 @@@\n      1\n      2\n      3\n    ++<<<<<<< FETCH_HEAD\n     +B2\n    ++=======\n    + A2\n    ++>>>>>>> local\n      4\n      5\n      6\n\n... and after `git add -u` and `git reset` (note showing line \"B2\" as \nunchanged, and now showing leftover \"conflicts\" around \"A1\" here as \nwell, where previous \"combined\" diff discarded it as uninteresting \ndue to implied \"--cc\"[4] flag):\n\n    $ git diff\n    diff --git a/A b/A\n    index 424ae9e..77ad8e6 100644\n    --- a/A\n    +++ b/A\n    @@ -2,7 +2,11 @@ A\n     1\n     2\n     3\n    +<<<<<<< FETCH_HEAD\n     B2\n    +=======\n    +A2\n    +>>>>>>> local\n     4\n     5\n     6\n    @@ -13,5 +17,9 @@ A3\n     2\n     3\n     4\n    +<<<<<<< FETCH_HEAD\n     B1\n    +=======\n    +A1\n    +>>>>>>> local\n     5\n\n\nHope that helps. As usual, best to give it some try on your own :)\n\nRegards, Buga\n\n[1] https://git-scm.com/docs/git-diff#_diff_format_for_merges\n[2] https://git-scm.com/docs/git-diff#_combined_diff_format\n[3] https://git-scm.com/docs/git-diff\n[4] https://git-scm.com/docs/git-diff-tree#git-diff-tree---cc\n"}]}