-1

For example:

$ git status
On branch master
You have unmerged paths.
  (fix conflicts and run "git commit")
  (use "git merge --abort" to abort the merge)

Unmerged paths:
  (use "git add <file>..." to mark resolution)

    both modified:   test.txt
$ git ls-files
test.txt
test.txt
test.txt

Is there any way to make it list files of this kind only once too? I only need the file names.

Dmitry
  • 3,625
  • 2
  • 30
  • 28
  • 1
    Consider using `git status --porcelain` or `git status --porcelain=v2` for machine-readable output. Or, use `git ls-files --stage` and parse the full output. – torek May 19 '20 at 22:23
  • Good suggestion, but `git status` does not support all the options I need. In particular, there's no way to include the unmodified files in the output. – Dmitry May 19 '20 at 22:48

2 Answers2

2

That happens when there is a conflict. Each one of them is a different version of the file. Check with:

git ls-files -s

Take a look at git help read-tree, the section about 3-way merge. The important part for you is this: ...and you will end up with an index with all of the <tree1> entries in "stage1", all of the <tree2> entries in "stage2" and all of the <tree3> entries in "stage3". When performing a merge of another branch into the current branch, we use the common ancestor tree as <tree1>, the current branch head as <tree2>, and the other branch head as <tree3>

eftshift0
  • 26,375
  • 3
  • 36
  • 60
1

Is there any way to make it list files of this kind only once too?

git ls-files | sort -u

Git tends not to duplicate existing tools.

jthill
  • 55,082
  • 5
  • 77
  • 137