【问题标题】:`git ls-files` includes unmerged files thrice`git ls-files` 包含三次未合并的文件
【发布时间】:2020-09-06 03:28:35
【问题描述】:

例如:

$ 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

有没有办法让它也只列出一次这种类型的文件?我只需要文件名。

【问题讨论】:

  • 考虑使用git status --porcelaingit status --porcelain=v2 以获得机器可读的输出。或者,使用 git ls-files --stage 并解析完整的输出。
  • 好建议,但git status 不支持我需要的所有选项。特别是,无法在输出中包含未修改的文件。

标签: git git-ls-files


【解决方案1】:

发生冲突时会发生这种情况。它们中的每一个都是文件的不同版本。检查:

git ls-files -s

看看git help read-tree,关于3-way merge的部分。对您来说重要的部分是:...and you will end up with an index with all of the &lt;tree1&gt; entries in "stage1", all of the &lt;tree2&gt; entries in "stage2" and all of the &lt;tree3&gt; entries in "stage3". When performing a merge of another branch into the current branch, we use the common ancestor tree as &lt;tree1&gt;, the current branch head as &lt;tree2&gt;, and the other branch head as &lt;tree3&gt;

【讨论】:

  • 是的,问题是关于冲突文件。
  • 这个答案很好,但对我个人来说并没有什么新的东西。不过,请投赞成票。谢谢。
  • 如果您只想查看一次,您可以使用 git 之外的工具:git ls-files | uniq。也许将其保留为(bash)别名?
  • 我在脚本中使用它。恩,uniq 不错,谢谢。
【解决方案2】:

有没有办法让它也只列出一次这种类型的文件?

git ls-files | sort -u

Git 不会复制现有工具。

【讨论】:

    猜你喜欢
    • 2020-01-03
    • 2021-12-19
    • 2021-06-19
    • 2020-08-06
    • 1970-01-01
    • 1970-01-01
    • 2016-08-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多