代码之家  ›  专栏  ›  技术社区  ›  Saransh Kejriwal

git add-只添加“both modified:”文件的标志

  •  1
  • Saransh Kejriwal  · 技术社区  · 7 年前

    让我介绍一个场景-我正在进行回购,在 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 file2 已被接受 其他分支机构 并已准备好提交。

    我在中遇到合并冲突 file3 file4 ,这是我在编辑器上手动修复的。

    我对 file5 file6 但是我还不愿意承担那些…

    我已经添加了 file7 file8 到工作区,但我也不愿意承诺这些。

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

    git add file1
    git add file2
    

    有什么旗子吗 在里面 git add ,我只能使用其中的文件 both modified 状态,同时忽略已修改和未保存的文件?

    谢谢

    1 回复  |  直到 7 年前
        1
  •  1
  •   VonC    6 年前

    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)
    
    推荐文章