git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: how to automatically open conflicted files when "git rebase" encounter conflict

From
brian m. carlson <sandals@crustytoothpaste.net>
Date
Mar 18, 2022, 20:14 UTC
Message-ID
<YjToDb9Mz9Q9z4Bq@camp.crustytoothpaste.net>
In-Reply-To
<bc7b04de-17be-df86-1c93-792903eeec9b@mails.ucas.ac.cn>
On 2022-03-18 at 02:00:52, wuzhouhui wrote:
Show 7 quoted lines
> Hi
> 
> When "git rebase" stopped due to conflict, I have to manually open
> conflicted
> file one by one and resolve conflict, and the typing file path is too
> boring.
> So, how to automatically open (e.g. use Vim) conflicted files?

I agree that in the typical project with a few levels of directories this is a hassle.

Fortunately, there are lots of ways to do this. The way I happen to do it is with an alias:

  [alias]
    conflicted = "!f() { git status -s | grep -E '^(DD|AA|.U|U.)' | cut -b4-; };f"
and then I run this:
  git conflicted | xargs nvim-gtk

To preempt someone pointing this out, you would want to use "git status --porcelain" for scripting instead of "git status -s", but I happen to know what I'm doing in this particular case (and have reasons for it) and can fix things if it breaks. You should probably use --porcelain.

My approach also works less well if you have files with spaces or other characters special to the shell. That can be fixed with using NUL-terminated strings if that's a problem for you (it isn't on the projects I work on).

-- 
brian m. carlson (he/him or they/them)
Toronto, Ontario, CA
Previous: Junio C HamanoNext: Junio C Hamano
Message 7 of 8 in “how to automatically open conflicted files when "git rebase" encounter conflict”
  1. wuzhouhuiMar 18, 2022
  2. Junio C HamanoMar 18, 2022
  3. Erik Cervin EdinMar 18, 2022
  4. wuzhouhuiMar 19, 2022
  5. Erik Cervin EdinMar 18, 2022
  6. Junio C HamanoMar 18, 2022
  7. brian m. carlsonMar 18, 2022
  8. Junio C HamanoMar 18, 2022

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.