0

I am currently working on merging from test branch to master branch. I use the command below to see the differences.

git difftool master_banch test_branch

I set default for difftool is vimdiff. I was wondering how we are going to save the file after we edit changes and stop launching the next files? I have more than 1000 files to edit between master and test branch, so if I want to save it and continue to work next day, how I am going to stop and save it?

I tried with editing the files and save by using :wq on vim, so after I edited the first file, it will automatically go the second file. When I used Ctrl+C to stop, all the changes are gone.

Kevin K
  • 19
  • 1
  • 5
  • 1
    did you try `:wqa!`? Should quit all files – wxz Apr 22 '21 at 23:33
  • @wxz `git difftool` invokes the editor repeatedly, once for each file that differs. `:wqa!` will exit one such editor instance; OP is asking how to prevent further ones from being launched. – Amadan Apr 23 '21 at 03:54

2 Answers2

1

To answer the literal question, you can use

git difftool --trust-exit-code ...

(or the equivalent .gitconfig setting) to allow difftool to abort and not proceed with further files if the difftool (i.e. vim) returns an error exit code. You can make vim return an error exit code using :cquit (:cq). The changes will be lost unless you saved beforehand (using :w or :up).

Amadan
  • 191,408
  • 23
  • 240
  • 301
0

The git difftool command is not, in general, meant for for editing files. See my answer to How difftool can show branch changes but avoiding merges? for more about how git difftool is designed.

Doing very large merges in Git (or anywhere, really) can be difficult. The usual solution to this problem is to avoid doing large merges. Git's design encourages frequent small commits, which can be merged with frequent small merges, which are generally far easier and less error-prone. But that's something to be addressed in the future; you have a large merge problem now, and you must deal with it.

The way to deal with it is not to use git difftool. Just don't run git difftool at all. If you want to have access to all the files from the two branches of interest accessible somewhere, consider using git worktree add for this purpose instead. (Caveat: make sure you have Git version 2.15 or later, if possible; git worktree was new in Git 2.5 and has a few nasty surprises in it that were finally fixed in 2.15. For just viewing files, the implementation in Git 2.5 is fine, though.)

To perform a merge, pick some working tree—such as the main one, rather than one added with git worktree add—and begin the merge. Proceed with it until it is complete. Do not try to use this working tree for any other purpose while you use it for merging.

If you don't have git worktree, note that you can just make multiple clones of a repository. Use one clone in which to do the merge; use the other clone(s) to view files from particular commits, including the branch tips that you are merging.

torek
  • 448,244
  • 59
  • 642
  • 775