Git resolve conflict using --ours/--theirs for all files

前端 未结 6 665

Is there a way to resolve conflict for all files using checkout --ours and --theirs? I know that you can do it for individual files but couldn\'t f

6条回答
  •  鱼传尺愫
    2020-12-22 17:42

    Just grep through the working directory and send the output through the xargs command:

    grep -lr '<<<<<<<' . | xargs git checkout --ours
    

    or

    grep -lr '<<<<<<<' . | xargs git checkout --theirs
    

    How this works: grep will search through every file in the current directory (the .) and subdirectories recursively (the -r flag) looking for conflict markers (the string '<<<<<<<')

    the -l or --files-with-matches flag causes grep to output only the filename where the string was found. Scanning stops after first match, so each matched file is only output once.

    The matched file names are then piped to xargs, a utility that breaks up the piped input stream into individual arguments for git checkout --ours or --theirs

    More at this link.

    Since it would be very inconvenient to have to type this every time at the command line, if you do find yourself using it a lot, it might not be a bad idea to create an alias for your shell of choice: Bash is the usual one.

    This method should work through at least Git versions 2.4.x

提交回复
热议问题