简体   繁体   English

Git跟踪未跟踪的文件而不添加提交

[英]Git track untracked files without adding to commit

I ran the command "git reset", but my unstaged changes were put into folders instead. 我运行了“ git reset”命令,但是我的未暂存更改已放入文件夹中。 I get something like the following after running git status: 运行git status后,我得到如下内容:

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:   file1
    modified:   file2
    modified:   file3
    modified:   file4
    modified:   file5

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

    folder1
    folder2
    folder3
    folder4

Each of the folders contains multiple files which I modified, but were for some reason grouped into these folders. 每个文件夹都包含我修改过的多个文件,但是由于某种原因被归类到这些文件夹中。

I need to separate these changes into multiple pull requests, so "git commit -a" won't do. 我需要将这些更改分成多个拉取请求,因此“ git commit -a”将不会执行。

The best solution I see is to "git add -all", copy the "git status", and "git reset" again, but that seems like a lot of effort. 我看到的最佳解决方案是“ git add -all”,复制“ git status”,然后再次“ git reset”,但这似乎很费劲。

Is there a better solution? 有更好的解决方案吗?

Git only tracks files (not folders / directories). Git仅跟踪文件(不跟踪文件夹/目录)。

However, for optimization purposes, git status reports untracked files within a sub-directory / folder using an abbreviated format, if possible. 但是,出于优化目的,如果可能, git status使用缩写格式报告子目录/文件夹中未跟踪的文件。

To de-abbreviate, use git status -uall (that's -u + all , as in "show me all the files, not a shortened list"). 要取消缩写,请使用git status -uall (即-u + all ,如“向我显示所有文件,而不是简短列表”中所述)。 You can also write -uno meaning show no files, or just -u which means -uall anyway. 您还可以编写-uno表示显示文件,或者仅-u表示-uall The default is -unormal , which is the normal abbreviated version. 缺省值为-unormal ,这是常规的缩写版本。

You can add any individual file, eg: 您可以添加任何单个文件,例如:

git add folder1/foo.txt

and now that file is tracked, and git status can no longer abbreviate: it must list all still-untracked files in folder1/ one at a time, since folder1/foo.txt is tracked. 现在该文件已被跟踪,并且git status不再缩写:由于必须跟踪folder1/foo.txt ,它必须一次列出folder1/中所有仍未跟踪的文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM