How to track but not stage and how to unstage but not untrack?

后端 未结 2 990
长情又很酷
长情又很酷 2021-02-02 05:10

I have two concise questions:

  • How I can track files but without staging them ?
  • How I can unstage files for commit without untracking them ?

2条回答
  •  栀梦
    栀梦 (楼主)
    2021-02-02 06:13

    Update (May 2015)

    I tried to use git add -N but it tracks the file and add it for commit:

    That is no longer the case with the upcoming Git 2.5 (Q2 2015).
    See "File doesn′t get into the commit after using git add -N"


    Original answer (March 2013)

    How I can unstage files for commit without untracking them ?

    this is the official way:

    git reset HEAD fileA
    

    But since it is a new file, you would untrack it as well (remove it from the index, without any previous commit referencing it).

    Starting tracking a file means having it in a index (stage) or a commit.

    I would recommend making a branch for those files, in order to add them/commit them there.
    See "What is Tracked files and Untracked files in the context of GIT?"

    • Tracked files are files that were in the last snapshot; they can be unmodified, modified, or staged.
    • Untracked files are everything else — any files in your working directory that were not in your last snapshot and are not in your staging area (index)

    That means that, for a new file, unstaged it means untrack it.


    (Source: Pro Git Book, 2.2 Git Basics - Recording Changes to the Repository)
    (Thank you, louisfischer, for the update/fix in the comments)

    See also "git - how to tell if a file is git tracked (by shell exit code)?".

提交回复
热议问题