如何追踪而不是阶段,以及如何取而不开,而不是追踪? [英] How to track but not stage and how to unstage but not untrack?

查看:106
本文介绍了如何追踪而不是阶段,以及如何取而不开,而不是追踪?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个简洁的问题:


  • 如何追踪文件但不登陆它们?
  • 如何在不解除提交文件的情况下取消提交文件?
  • 我可以做一个初始提交来跟踪这些文件,并从那里跟踪我的文件。但有可能专门做我上面提到的问题吗?



    我尝试使用 git add -N< expr> 但它跟踪文件并将其添加到commit:

      PS C:\> git add -N fileA 
    PS C:\> git status
    #在分支主机上
    #要提交的更改:
    #(使用git reset HEAD< file> ...停用)

    #新文件:fileA

    #没有为commit提交的更改:
    #(使用git add< file> ...更新将提交的内容)
    #(使用git checkout - < file> ...放弃工作目录中的更改)

    #修改:README.md
    #修改:composer.lock
    #modified:fileA

    如果我做 git reset HEAD fileA git rm --cached fileA 取消它的作用,但也会解除对文件的处理。
    这个命令 git rm fileA 建议我使用标志-f来删除文件。



    所以,有可能只跟踪,而不是阶段,并且只能暂停而不是未跟踪文件? 解决方案

更新2015)


我尝试使用 git add -N 但它跟踪文件并将其添加到提交中:

即将推出的Git 2.5(2015年第2季度)
请参阅

(来源: Pro Git Book ,2.2 Git基础知识 - 记录对存储库的更改

(谢谢, louisfischer ,以便更新/修复

另请参阅


I have two concise questions:

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

NOTE: I know that I can do an initial commit to track the files and start from there with my files tracked. But is possible to specifically do what I'm asking above ?

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

PS C:\> git add -N fileA
PS C:\> git status
# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#       new file:   fileA
#
# 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:   README.md
#       modified:   composer.lock
#       modified:   fileA
#

If I do git reset HEAD fileA or git rm --cached fileA unstages it but also untracks the file. This command git rm fileA suggest me to use the flag -f that removes the file fisically.

So, It is possible to only track but not stage, and to only unstage but not untrack files ?

解决方案

Update (May 2015)

I tried to use git add -N <expr> 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)?".

这篇关于如何追踪而不是阶段,以及如何取而不开,而不是追踪?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆