获取git不显示未跟踪的文件

chi*_*gsy 24 git

在做什么时git commit,有没有办法在我的编辑器中显示未跟踪的文件(定义$EDITOR)?我知道如何在shell(git status -uno)中这样做,但我也想在编辑器中这样做.

请注意,我不想永远忽略这些文件; 我只是不想在某些场合看到它们.

mip*_*adi 47

如果你不以往任何时候都希望将其提交到您的回购,使用.gitignore文件忽略它们.更多详细信息可以在gitignore手册页上找到.在您的帐户中输入提交邮件时,它们不会显示为未跟踪的文件$EDITOR.

如果你根本不希望看到他们提交时,设置的Git配置变量status.showUntrackedFiles,以no作为注意这里:

$ git config --global status.showUntrackedFiles no
Run Code Online (Sandbox Code Playgroud)

  • 如果你只想忽略当前仓库中未跟踪的文件,而不是全局使用:`git config --local status.showUntrackedFiles no` (12认同)

小智 20

git-commit手册页:

       -u[], --untracked-files[=]
           Show untracked files (Default: all).

           The mode parameter is optional, and is used to specify the handling of untracked
           files. The possible options are:

           ·   no - Show no untracked files

           ·   normal - Shows untracked files and directories

           ·   all - Also shows individual files in untracked directories.

               See git-config(1) for configuration variable used to change the default for
               when the option is not specified.


Loh*_*run 5

您可以临时使用git commit选项-uno来屏蔽未跟踪的文件(git help commit).

如果您想要永久解决方案,请使用该.gitignore文件.

例如,如果要忽略文件bar.foo和任何带.bak扩展名的文件,则必须.gitignore在项目的根目录中创建一个包含以下内容的文件:

bar.foo
*.bak
Run Code Online (Sandbox Code Playgroud)

某些文件被全局gitignore文件忽略(例如,忽略点文件和目录).


Jon*_*ler 5

将文件名 - 或文件名的模板(通配符) - 添加到 .gitignore 文件并将其添加到存储库:

git add .gitignore
git commit -m 'Added .gitignore file'
Run Code Online (Sandbox Code Playgroud)

例如,对于我的 Go 存储库,我有一个 .gitignore 文件,其中包含:

*.o
*.a
*.so
*.pl
*.6
*.out
_obj/
_cgo_defun.c
_cgo_export.c
_cgo_export.h
_cgo_gotypes.go
*.cgo1.go
*.cgo2.c
example/example
ifix1/esqlc-cmds.c
Run Code Online (Sandbox Code Playgroud)

我可能应该_cgo_用通配符压缩“ ”名称;另一个“.c”文件是从“.ec”文件生成的,因此不需要跟踪。


L S*_*L S 5

有时不需要有关更改的存储库文件或需要添加到存储库的新文件的通知。但是,添加文件名也.gitignore可能不是一个好的选择。例如,其他用户不太可能生成的本地生成的文件(例如,由编辑器创建的文件)或实验测试代码的文件可能不适合出现在文件中.gitignore

在这些情况下,请使用以下解决方案之一:

  1. 如果该文件是更改的存储库文件

    使用命令:

    git update-index --assume-unchanged "$FILE"

    要撤消此操作,请使用以下命令:

    git update-index --no-assume-unchanged "$FILE"

    不过,该update-index命令不适用于尚未添加到存储库的新文件。

  2. 如果文件是新的且未添加到存储库中

    将其文件名添加到存储库的exclude文件中:

    echo "$FILE" >> .git/info/exclude

    这也适用于更改的存储库文件,但没有特定的撤消命令。exclude需要编辑该文件并从中删除文件名。或者其他命令可以近似它:

    ex -s -c"g/^${FILE}\$/d" -cwq .git/info/exclude

    请注意,这会覆盖现有exclude文件,如果指定的文件名包含可能影响正则表达式的特殊字符,则结果将不可预测。

    GitHub 帮助上的“忽略文件”exclude页面建议使用该文件。