阻止在 Git 中跟踪配置和 html 文件



我最近克隆了另一个存储库。当我打开 Git GUI 时,我在左上角的"未暂存更改"部分看到文件列表。这些主要是css,html,.class,gif和xml文件。而且,我更改了一些Java文件。

几个问题:

  1. 如何防止这些配置和 html 文件出现在我的非暂存更改文件列表中?由于文件列表很长,我发现很难对单个文件执行其他操作,例如"还原更改"。请注意,过去克隆其他存储库时不会发生这种情况。我需要 .gitignore 文件吗?

  2. 当我尝试使用 git pull 从存储库中提取最新更改时,我收到消息"您的本地更改...将被覆盖"。在这种情况下,是先提交更改更好,还是只是还原更改并拉取然后重新添加旧更改?

我需要 .gitignore 文件吗?

这将解决列出未跟踪文件的问题。

例如

git status
# On branch master
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#   foo.bar
#   foo.html
echo "*.html" > .gitignore
git status
# On branch master
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#   foo.bar

是先提交我的更改更好,还是只是还原更改并拉取然后重新添加旧更改更好?

如果您打算在某个时候提交它们 - 清理代码更改并以其他方式提交它们/或者您可以使用 git stash 临时存储您的更改并在以后重新应用它们,例如:

hack
hack
hack
git stash
git pull
...
git stash pop # <- restore stashed changes

使用 git stash

http://git-scm.com/book/en/Git-Tools-Stashing

这使您可以同时保留两者

最新更新