我把以前由 Git 跟踪的文件放在.gitignore 列表中. 但是,文件在编辑后仍然显示在 git 状态。
当前回答
在我的情况下,我需要在.gitignore 文件中插入 ".envrc" 。
然后我用了:
git update-index --skip-worktree .envrc
git rm --cached .envrc
文件已被删除。
然后我再次承诺,说文件已被删除。
但当我使用 git log -p 命令时,文件的内容(这是 Amazon S3 的秘密认证)显示已删除的内容,我不想在 Git 存储库的历史上显示此内容。
然后我用了这个命令:
git filter-branch --index-filter 'git rm --cached --ignore-unmatch .envrc' HEAD
我再也不会看到内容了。
其他回答
特别是对于基于 IDE 的文件,我使用以下文件:
例如,对于 slnx.sqlite 文件,我刚刚完全解除它如下:
git rm {PATH_OF_THE_FILE}/slnx.sqlite -f
git commit -m "remove slnx.sqlite"
请记住,其中一些文件存储一些本地用户设置和项目偏好(类似于您打开的文件)。所以每次您浏览或在您的 IDE 中进行一些更改,该文件会被更改,因此它会检查并显示为未订购的更改。
答案来自Matt Frear是最有效的IMHO. 下面只是一个PowerShell脚本给那些在Windows只删除文件从他们的Git存储库,符合他们的排除列表。
# Get files matching exclusionsfrom .gitignore
# Excluding comments and empty lines
$ignoreFiles = gc .gitignore | ?{$_ -notmatch "#"} | ?{$_ -match "\S"} | % {
$ignore = "*" + $_ + "*"
(gci -r -i $ignore).FullName
}
$ignoreFiles = $ignoreFiles| ?{$_ -match "\S"}
# Remove each of these file from Git
$ignoreFiles | % { git rm $_}
git add .
更新您的.gitignore 文件 - 例如,添加一个文件夹,你不想跟踪到.gitignore. git rm -r --cached. - 删除所有跟踪的文件,包括所需和不需要的. 您的代码将是安全的,只要你保存了本地. git 添加. - 所有文件将返回,除了那些在.gitignore.
请点击 @AkiraYamamoto 指向我们正确的方向。
在已承诺的DS_Store的情况下:
find . -name .DS_Store -print0 | xargs -0 git rm --ignore-unmatch
忽略它们:
echo ".DS_Store" >> ~/.gitignore_global
echo "._.DS_Store" >> ~/.gitignore_global
echo "**/.DS_Store" >> ~/.gitignore_global
echo "**/._.DS_Store" >> ~/.gitignore_global
git config --global core.excludesfile ~/.gitignore_global
最后,做一个承诺!
推荐文章
- 为什么我需要显式地推一个新分支?
- 如何撤消最后的git添加?
- Rubymine:如何让Git忽略Rubymine创建的.idea文件
- Gitignore二进制文件,没有扩展名
- Git隐藏错误:Git隐藏弹出并最终与合并冲突
- 了解Git和GitHub的基础知识
- 没有。Git目录的Git克隆
- Git与Mercurial仓库的互操作性
- 忽略git中修改(但未提交)的文件?
- “git restore”命令是什么?“git restore”和“git reset”之间有什么区别?
- Git合并与强制覆盖
- Git拉另一个分支
- 在Bash命令提示符上添加git分支
- 如何更改Git日志日期格式
- git pull -rebase和git pull -ff-only之间的区别