{"thread":{"id":"57581","subject":"how to automatically open conflicted files when \"git rebase\" encounter conflict","startedAt":"2022-03-18T02:01:02Z","lastAt":"2022-03-19T02:02:00Z","messageCount":8,"participants":["wuzhouhui","Junio C Hamano","Erik Cervin Edin","brian m. carlson"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"451616","messageId":"bc7b04de-17be-df86-1c93-792903eeec9b@mails.ucas.ac.cn","threadId":"57581","inReplyTo":null,"subject":"how to automatically open conflicted files when \"git rebase\" encounter conflict","fromName":"wuzhouhui","fromEmail":"wuzhouhui14@mails.ucas.ac.cn","sentAt":"2022-03-18T02:00:52Z","receivedAt":"2022-03-18T02:01:02Z","isPatch":false,"sender":{"key":"wuzhouhui14@mails.ucas.ac.cn","avatar":null},"body":"Hi\n\nWhen \"git rebase\" stopped due to conflict, I have to manually open \nconflicted\nfile one by one and resolve conflict, and the typing file path is too \nboring.\nSo, how to automatically open (e.g. use Vim) conflicted files?\n\nThanks.\n\n"},{"id":"451617","messageId":"xmqqtubvc32q.fsf@gitster.g","threadId":"57581","inReplyTo":"bc7b04de-17be-df86-1c93-792903eeec9b@mails.ucas.ac.cn","subject":"Re: how to automatically open conflicted files when \"git rebase\" encounter conflict","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2022-03-18T04:11:25Z","receivedAt":"2022-03-18T04:14:11Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"wuzhouhui <wuzhouhui14@mails.ucas.ac.cn> writes:\n\n> Hi\n>\n> When \"git rebase\" stopped due to conflict, I have to manually open\n> conflicted\n> file one by one and resolve conflict, and the typing file path is too\n> boring.\n> So, how to automatically open (e.g. use Vim) conflicted files?\n>\n> Thanks.\n\nPerhaps take \"git jump\" from contrib/ and do\n\n    $ GIT_EDITOR=vi git jump merge\n"},{"id":"451628","messageId":"CA+JQ7M8_QiidajaWJpz3gFeUXiLMLiDA38W1mnWyxnMLJN3fpQ@mail.gmail.com","threadId":"57581","inReplyTo":"bc7b04de-17be-df86-1c93-792903eeec9b@mails.ucas.ac.cn","subject":"Re: how to automatically open conflicted files when \"git rebase\" encounter conflict","fromName":"Erik Cervin Edin","fromEmail":"erik@cervined.in","sentAt":"2022-03-18T16:00:37Z","receivedAt":"2022-03-18T16:01:17Z","isPatch":false,"sender":{"key":"erik@cervined.in","avatar":null},"body":"On Fri, Mar 18, 2022 at 8:02 AM wuzhouhui <wuzhouhui14@mails.ucas.ac.cn> wrote:\n>\n> Hi\n>\n> When \"git rebase\" stopped due to conflict, I have to manually open\n> conflicted\n> file one by one and resolve conflict, and the typing file path is too\n> boring.\n> So, how to automatically open (e.g. use Vim) conflicted files?\n>\n\nHi!\n\nI rebase quite a lot and my strategy is as follows\n  git diff\nallows me to quickly overview the conflicted files and conflicts.\nUsually, I want to either take all *ours* (the stuff I've rebased\nonto) or *theirs* (the incoming rebased commit).\n\nTo do this quickly I've developed a script (basically glue-code of git => sed)\nhttps://github.com/CervEdin/gut/blob/main/git-resolve.sh\nwhich can be invoked\n  git resolve -o/t/b (--ours/theirs/both) 'pathspec'\nMore information on the underlying implementation can be found in this\nstackoverflow answer\nhttps://stackoverflow.com/a/68498101/\nThe script is something I've developed for my own use and very much\nnot bug free.\nNevertheless, I personally find it efficiently covers the case of\nbasic conflicts I encounter.\n\nIn the situations of more complicated conflicts (as well as the\nfunctionality you request) can be invoked using\n  git mergetool\n  git mergetool -- 'pathspec'\n  git mergetool --tool=vimdiff -- 'pathspec'\nThat is unless you want to solely use vim without vimdiff.\nThe main downside is that invoking mergetool is a bit slow :/\n"},{"id":"451629","messageId":"CA+JQ7M-2kRnHrTCErTOY5O=4PCbRc7DWOHt1q5DxXmCu6z7K1A@mail.gmail.com","threadId":"57581","inReplyTo":"xmqqtubvc32q.fsf@gitster.g","subject":"Re: how to automatically open conflicted files when \"git rebase\" encounter conflict","fromName":"Erik Cervin Edin","fromEmail":"erik@cervined.in","sentAt":"2022-03-18T16:01:36Z","receivedAt":"2022-03-18T16:02:13Z","isPatch":false,"sender":{"key":"erik@cervined.in","avatar":null},"body":"On Fri, Mar 18, 2022 at 4:38 PM Junio C Hamano <gitster@pobox.com> wrote:\n> Perhaps take \"git jump\" from contrib/ and do\n>\n>     $ GIT_EDITOR=vi git jump merge\n\nThis looks interesting. Thanks Junio\n"},{"id":"451639","messageId":"xmqqpmmj9l11.fsf@gitster.g","threadId":"57581","inReplyTo":"CA+JQ7M8_QiidajaWJpz3gFeUXiLMLiDA38W1mnWyxnMLJN3fpQ@mail.gmail.com","subject":"Re: how to automatically open conflicted files when \"git rebase\" encounter conflict","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2022-03-18T18:24:10Z","receivedAt":"2022-03-18T18:24:21Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Erik Cervin Edin <erik@cervined.in> writes:\n\n> In the situations of more complicated conflicts (as well as the\n> functionality you request) can be invoked using\n>   git mergetool\n>   git mergetool -- 'pathspec'\n>   git mergetool --tool=vimdiff -- 'pathspec'\n\nYeah, I forgot all about \"git mergetool\".  I think that is the\nofficial answer to the original question.\n"},{"id":"451642","messageId":"YjToDb9Mz9Q9z4Bq@camp.crustytoothpaste.net","threadId":"57581","inReplyTo":"bc7b04de-17be-df86-1c93-792903eeec9b@mails.ucas.ac.cn","subject":"Re: how to automatically open conflicted files when \"git rebase\" encounter conflict","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2022-03-18T20:14:05Z","receivedAt":"2022-03-18T20:14:48Z","isPatch":false,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"On 2022-03-18 at 02:00:52, wuzhouhui wrote:\n> Hi\n> \n> When \"git rebase\" stopped due to conflict, I have to manually open\n> conflicted\n> file one by one and resolve conflict, and the typing file path is too\n> boring.\n> So, how to automatically open (e.g. use Vim) conflicted files?\n\nI agree that in the typical project with a few levels of directories\nthis is a hassle.\n\nFortunately, there are lots of ways to do this.  The way I happen to do\nit is with an alias:\n\n  [alias]\n    conflicted = \"!f() { git status -s | grep -E '^(DD|AA|.U|U.)' | cut -b4-; };f\"\n\nand then I run this:\n\n  git conflicted | xargs nvim-gtk\n\nTo preempt someone pointing this out, you would want to use \"git status\n--porcelain\" for scripting instead of \"git status -s\", but I happen to\nknow what I'm doing in this particular case (and have reasons for it)\nand can fix things if it breaks.  You should probably use --porcelain.\n\nMy approach also works less well if you have files with spaces or other\ncharacters special to the shell.  That can be fixed with using\nNUL-terminated strings if that's a problem for you (it isn't on the\nprojects I work on).\n-- \nbrian m. carlson (he/him or they/them)\nToronto, Ontario, CA\n"},{"id":"451645","messageId":"xmqqv8wb6jhw.fsf@gitster.g","threadId":"57581","inReplyTo":"YjToDb9Mz9Q9z4Bq@camp.crustytoothpaste.net","subject":"Re: how to automatically open conflicted files when \"git rebase\" encounter conflict","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2022-03-18T21:25:31Z","receivedAt":"2022-03-18T21:25:37Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"brian m. carlson\" <sandals@crustytoothpaste.net> writes:\n\n> Fortunately, there are lots of ways to do this.  The way I happen to do\n> it is with an alias:\n>\n>   [alias]\n>     conflicted = \"!f() { git status -s | grep -E '^(DD|AA|.U|U.)' | cut -b4-; };f\"\n>\n> and then I run this:\n>\n>   git conflicted | xargs nvim-gtk\n>\n> To preempt someone pointing this out, you would want to use \"git status\n> --porcelain\" for scripting instead of \"git status -s\", but I happen to\n> know what I'm doing in this particular case (and have reasons for it)\n> and can fix things if it breaks.  You should probably use --porcelain.\n\nI wonder if adding \"--name-only\" support to \"ls-files\" helps here.\nIt would make the above\n\n    git ls-files [-z] --name-only -u | xargs [-0] editor\n\nAs your \"grep -E\" pattern indicates, \"status\" makes another\ncomparison with HEAD that we do not even use, when we only need to\nlist the unmerged paths in the index.\n\nThere is no \"--[no-]name-only\", and \"-s\" (for obvious reasons) asks\nto show the mode, stage, and the object name information.  When we\nadded \"-u\", we said \"if you are asking for conflicted paths, you of\ncourse want to know the stage information\" without questioning the\nwisdom of that decision, especially as Linus and I were both in the\nmindset to produce a small building-block to be used in a script\nback then, and for a tool that deals with an unmerged index, having\nthe path alone is not all that useful.\n\nBut with time, we learn more needs out of our existing tools.\n\n"},{"id":"451659","messageId":"550558de-7847-ee2e-171b-1e03f2daf570@mails.ucas.ac.cn","threadId":"57581","inReplyTo":"xmqqtubvc32q.fsf@gitster.g","subject":"Re: how to automatically open conflicted files when \"git rebase\" encounter conflict","fromName":"wuzhouhui","fromEmail":"wuzhouhui14@mails.ucas.ac.cn","sentAt":"2022-03-19T02:01:46Z","receivedAt":"2022-03-19T02:02:00Z","isPatch":false,"sender":{"key":"wuzhouhui14@mails.ucas.ac.cn","avatar":null},"body":"On 3/18/22 12:11, Junio C Hamano wrote:\n> wuzhouhui <wuzhouhui14@mails.ucas.ac.cn> writes:\n>\n>> Hi\n>>\n>> When \"git rebase\" stopped due to conflict, I have to manually open\n>> conflicted\n>> file one by one and resolve conflict, and the typing file path is too\n>> boring.\n>> So, how to automatically open (e.g. use Vim) conflicted files?\n>>\n>> Thanks.\n> Perhaps take \"git jump\" from contrib/ and do\n>\n>      $ GIT_EDITOR=vi git jump merge\nThanks everyone, The \"git jump merge\" satisfies my needs.\n\n"}]}