sindrets / diffview.nvim

Single tabpage interface for easily cycling through diffs for all modified files for any git rev.
Other
3.6k stars 101 forks source link

[Question] 3-way layout becomes 2-way after staging during rebase #410

Closed OopsYao closed 11 months ago

OopsYao commented 11 months ago

Hi, when I open DiffviewOpen during rebasing, the 3-way diff layout appears as expected. But when I try to stage changes in the working tree buffer using commands like gitsigns's stage_hunk, the 3-way diff layout becomes a normal 2-way diff layout --- only the index and working tree buffer. And even after I recover the index by git restore --staged . and close&rerun DiffviewOpen, there is only the 2-way diff layout. So I'm wondering that is this behavior intended and how do I stage changes during rebasing, provided that there is no index buffer in a 3-way diff layout?

NVIM v0.9.1 Build type: Release LuaJIT 2.1.0-beta3 git version 2.41.0 Linux 6.4.9-arch1-1 x86_64 GNU/Linux Health check

diffview: require("diffview.health").check()

Checking plugin dependencies ~
- OK nvim-web-devicons installed.

Checking VCS tools ~
- The plugin requires at least one of the supported VCS tools to be valid.
- OK Git found.
- OK Git is up-to-date. (2.41.0)
- WARNING Configured `hg_cmd` is not executable: 'hg'
sindrets commented 11 months ago

I'm not sure how familiar you are with Git stages. Git uses multiple stage areas to store temporary versions of a file in its index. Stage 0 represents the changes to be committed (i.e. what people normally talk about when they're talking about "staging"). During a conflict, stage 1-3 contains the different versions of a conflicted file.

For better or worse, the way Git is designed; putting anything in stage 0 during a conflict will signal to Git that the conflict is resolved and it will clear stage 1-3.

So to answer your question about "how do I stage changes during [a conflict]": you need to make all your wanted changes to a file, and then you stage the whole file. From the file panel you can do this with -.

and even after I recover the index by git restore --staged . and close&rerun DiffviewOpen, there is only the 2-way diff layout

git-restore has a specific flag for restoring a merge conflict: git restore --merge path/to/file. If you have the local file open in nvim you can do this simply with:

:!git restore --merge %
OopsYao commented 11 months ago

Oh, I never heard of these before and confuse the index in normal cases with merging ones. Thanks for your kind reply!

git-restore has a specific flag for restoring a merge conflict: git restore --merge path/to/file. If you have the local file open in nvim you can do this simply with:

:!git restore --merge %

I tried this command, and it recovers both index and working tree to the conflict state, in other words, it feels like to abort the merge then start over. Is there any way to just recover the index to the conflict state while keeping the working tree untouched? Or is there any misunderstanding of mine about the workflow in merging?