我把以前由 Git 跟踪的文件放在.gitignore 列表中. 但是,文件在编辑后仍然显示在 git 状态。
当前回答
要总结一下:
您的应用程序正在寻找一个被忽略的文件 config-overide.ini 并使用它在承诺的文件 config.ini (或替代,寻找 ~/.config/myapp.ini,或 $MYCONFIGFILE) 承诺文件 config-sample.ini 并忽略文件 config.ini,有脚本或类似的复制文件如有必要。
其他回答
例如,在使用 CVS 时,这个问题不存在, CVS 将信息存储为基于文件的变更列表。
这两篇文章对我很有帮助:
git assume-unchanged vs skip-worktree 以及如何用 Git 忽略跟踪文件的变化
git update-index --skip-worktree <file>
从此,此文件中的所有本地变更将被忽视,不会去远程。如果文件在远程中被更改,冲突将发生,当 git pull. Stash 不会工作。
git update-index --no-skip-worktree <file>
git stash
git pull
文件内容将被远程内容取代. 将您的更改从安全地点调整到文件,然后再次执行:
git update-index --skip-worktree <file>
在我的情况下,我需要在.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
我再也不会看到内容了。
我用 git filter-branch 完成了这一点,我所使用的准确命令从 man 页面上取出:
警告:此将从您的整个历史中删除文件
git filter-branch --index-filter 'git rm --cached --ignore-unmatch filename' HEAD
这个命令将恢复整个命令历史,在每个命令之前执行 git rm 以便摆脱所指定的文件. 不要忘记在运行命令之前备份它,因为它将失去。
此方法需要使用 /.git/info/exclude 文件(偏好)或预先存在的.gitignore 在所有有文件要被忽视/忘记的任务中。
执行Git的所有方法都忽略了后事实行为,有效地重写历史,从而对任何公共/共享/合作的存储库产生了显著的分裂,这些存储库可能在这个过程之后被撤回。
#Commit up-to-date .gitignore (if not already existing)
#This command must be run on each branch
git add .gitignore
git commit -m "Create .gitignore"
#Apply standard Git ignore behavior only to the current index, not the working directory (--cached)
#If this command returns nothing, ensure /.git/info/exclude AND/OR .gitignore exist
#This command must be run on each branch
git ls-files -z --ignored --exclude-standard | xargs -0 git rm --cached
#Commit to prevent working directory data loss!
#This commit will be automatically deleted by the --prune-empty flag in the following command
#This command must be run on each branch
git commit -m "ignored index"
#Apply standard git ignore behavior RETROACTIVELY to all commits from all branches (--all)
#This step WILL delete ignored files from working directory UNLESS they have been dereferenced from the index by the commit above
#This step will also delete any "empty" commits. If deliberate "empty" commits should be kept, remove --prune-empty and instead run git reset HEAD^ immediately after this command
git filter-branch --tree-filter 'git ls-files -z --ignored --exclude-standard | xargs -0 git rm -f --ignore-unmatch' --prune-empty --tag-name-filter cat -- --all
#List all still-existing files that are now ignored properly
#If this command returns nothing, it's time to restore from backup and start over
#This command must be run on each branch
git ls-files --other --ignored --exclude-standard
git push origin --force --all
git push origin --force --tags
git for-each-ref --format="delete %(refname)" refs/original | git update-ref --stdin
git reflog expire --expire=now --all
git gc --prune=now
其他从已修改的远程存储库中提取的开发人员应该进行备份,然后:
#fetch modified remote
git fetch --all
#"Pull" changes WITHOUT deleting newly-ignored files from working directory
#This will overwrite local tracked files with remote - ensure any local modifications are backed-up/stashed
git reset FETCH_HEAD
脚印
告诉你的合作伙伴放弃,不要合并,他们创建的任何分支从你的旧(封闭)存储库历史。 一个合并承诺可以重新引入一些或所有的封闭的历史,你刚刚走到清理问题。
如果有人在Windows上有艰难的时间,你想忽略整个文件夹,请在文件探测器上转到所需的“文件夹”,右键单击并进行“Git Bash Here”(Git for Windows 应该安装)。
执行此命令:
git ls-files -z | xargs -0 git update-index --assume-unchanged
推荐文章
- 如何从远程分支中挑选?
- 如何查看一个分支中的哪些提交不在另一个分支中?
- 如何取消在github上的拉请求?
- HEAD和master的区别
- GIT克隆在windows中跨本地文件系统回购
- RPC失败;卷度传输已关闭,剩余未完成的读取数据
- 我应该在.gitignore文件中添加Django迁移文件吗?
- 错误:您对以下文件的本地更改将被签出覆盖
- Git rebase—即使所有合并冲突都已解决,仍然会继续报错
- 在Git中,我如何知道我的当前版本是什么?
- 跟踪所有远程git分支作为本地分支
- 自定义SSH端口上的Git
- git如何显示不存在于.gitignore中的未跟踪文件
- Git错误:遇到7个文件应该是指针,但不是
- GitHub克隆与OAuth访问令牌