【问题标题】:How to interactively add untracked file in Git?如何在 Git 中以交互方式添加未跟踪的文件?
【发布时间】:2016-01-26 19:44:40
【问题描述】:

我经常使用 git add -p 在 Git 中分段提交文件,但这不适用于未跟踪的文件:

$ git add -p file
No changes.

如何添加此文件,但不能全部暂存?

我只想添加其中的一部分并提交,其余部分不暂存。

【问题讨论】:

    标签: git version-control interactive


    【解决方案1】:

    您可以分两步完成:

    1. git add -N file

    来自man page

    -N, --intent-to-add 仅记录稍后将添加路径的事实。路径的条目被放置在没有内容的索引中。这很有用 除其他外,用于显示此类文件的未暂存内容 使用git diff 并使用git commit -a 提交它们。

    此命令会将文件添加为空,因此不会再取消跟踪,但不会暂存。

    # Initial commit
    #
    # Changes to be committed:
    #   (use "git rm --cached <file>..." to unstage)
    #
    #   new file:   file
    #
    # 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:   file
    #
    
    1. git add -p file

    现在文件已被跟踪,git add -p 可以正常工作。

    【讨论】:

      猜你喜欢
      • 2017-12-30
      • 2015-08-05
      • 2016-02-07
      • 2016-02-04
      • 2012-01-07
      • 1970-01-01
      • 1970-01-01
      • 2023-03-20
      • 2018-11-10
      相关资源
      最近更新 更多