Advanced linux shell wizardry - ParticulateFlow/OSCCAR-doc GitHub Wiki

A loose collection of magical linux shell stuff that might come in handy

Find and open all files which need a manual merge conflict resolution

We can split our task into smaller, easier tasks. We start from the set of all files and narrow our selection down until we get the set of files that meet the above stated criterion.

  1. Find all files in our repository (that's kind of dumb, but we do it anyway)
  2. Search all of the files we just found for a typical sequence generated by git to indicate a merge conflict, such as <<<<<<< HEAD
  3. Extract the proper file names. grep gives us an output like this Path/File:Line_containing_search_pattern. Thus, we need to extract the full path to the file, i.e. everything prior to the colon.
  4. Open the corresponding files with an editor of choice.

The following command, or rather chain of commands, does exactly what we just stated.

find . -type f | xargs grep '<<<<<<< HEAD' | cut -d: -f1 | xargs gedit

  1. find is used for generating a list of all files present in the current directory and below.
  2. grep is used to match a pattern
  3. cut is used to edit the output of grep
  4. gedit is our (my) trusted editor