git add-仅添加“两个已修改:”文件的标志

时间:2018-07-10 06:51:15

标签: git git-merge merge-conflict-resolution

让我介绍一个场景-我正在my_branch分支下的仓库中工作,我需要将other_branch的更改合并到我的分支。

我运行了命令: git merge origin/feature/other_branch

下面是运行此命令后的示例git status

$ git status
On branch feature/my_branch
Your branch is up-to-date with 'origin/feature/my_branch'.
You have unmerged paths.
  (fix conflicts and run "git commit")

Changes to be committed:

        modified:   file1
        modified:   file2

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

        both modified:   file3
        both modified:   file4

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

        modified:   file5
        modified:   file6        

Untracked files:
  (use "git add <file>..." to include in what will be committed)

        file7
        file8

如您所见,file1已接受对file2other_branch的更改,并且已暂存以提交。

我在file3file4中遇到了合并冲突,这些问题已在编辑器上手动修复。

我对file5file6进行了一些更改,但是我还不愿意提交这些内容...

我已经将file7file8添加到了工作区中,但是我也不愿意提交它们。

要将有冲突的文件添加到阶段,我需要运行:

git add file1
git add file2

git add中是否有一些标记,使用该标记,我只能将处于both modified状态的文件,而忽略已修改和未暂存的文件?

谢谢

1 个答案:

答案 0 :(得分:1)

git add本身没有这样的标记。

但是它可以将文件列表作为参数。
您可以list unmerged files

git diff --name-only --diff-filter=U

因此,类似的方法可能会起作用(using this to bring all files in one line):

git add $(git diff --name-only --diff-filter=U | xargs)