`git ls-files` includes unmerged files thrice

236 views Asked by At

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.

2

There are 2 answers

4
eftshift0 On

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>

0
jthill On

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.