我有一个包含敏感数据的文件,所以我不想将此文件的内容推送到远程服务器.
为了实现这一点,我在文件为空时进行了提交,并将此空文件推送到服务器(GitHub).然后用敏感数据填充文件并应用git update-index --skip-worktree path/to/file.但我没有做出任何承诺.
现在我正在尝试切换我的分支,但是我收到了这个错误:
error: Your local changes to the following files would be overwritten by checkout:
path/to/file
Please, commit your changes or stash them before you can switch branches.
Aborting
Run Code Online (Sandbox Code Playgroud)
skip-worktreeINSTEAD OF assume-unchanged?我读了几个关于这个问题的SO问题,并找到了Borealid的答案.
--assume-unchanged假定开发人员不应更改文件.此标志用于提高SDK等不可更改文件夹的性能.
- 当你指示git不要触摸特定文件时, - skip-worktree非常有用,因为开发人员应该更改它.例如,如果主存储库上游托管了一些生产就绪配置文件,并且您不想意外地提交对这些文件的更改,那么--skip-worktree正是您想要的.
在此之后,我发现了Jeff的问题和VonC的回答.杰夫的问题与我的问题几乎相同,我遵循了VonC的解决方案.但是这对我不起作用.也许是因为git版本的差异.因为这个问题来自2012年.我们与VonC进行了交谈,他说这是一个新问题,因为他不记得答案了.
我试图使用--assume-unchanged和--skip-worktree 在一起,软正在重置worktree.但没有改变.
你能帮我解决一下我的问题吗?
谢谢.
我已git update-index --skip-worktree <file>按照此处的建议使用git忽略对跟踪文件的本地更改.但现在我忘记了我应用它的文件.如何列出应用了skip-worktree标志的所有文件?
我正在尝试运行以下内容:
git update-index --assume-unchanged myFolderToIgnore
Run Code Online (Sandbox Code Playgroud)
myFolderToIgnore文件夹在哪里.然而它没有说它"无法标记"它.
所以我尝试过:
git update-index --assume-unchanged myFolderToIgnore/
Run Code Online (Sandbox Code Playgroud)
哪个GIT响应Ignoring path myFolderToIgnore/但没有做任何事情(它仍然看到我的更改并尝试检查它们).
最后,我必须进入并手动将每个文件标记为未更改.我在这里错过了什么?
我已经在github上分叉了一个项目,并开始在我自己的机器上乱搞它,我想提交我在github上回到我的fork的更改,但没有提交我对.cfg文件所做的更改,因为它包含像db密码等的东西
我对我的git工作目录中的文件进行了任意更改.
git status 无法识别文件已更改.
git add /path/to/file 没有效果.
git add -f /path/to/file 没有效果.
git status /path/to/file 将文件显示为"要提交的更改"存储区中的文件.
我删除了我的.gitignore文件,只是为了确定.上述任何行为均无变化.
我做了git reset --hard,重新做了我的改变.上述任何行为均无变化.
这可能会发生什么?
我需要在file.txt本地和Git中使用不同的内容.我希望Git不要告诉我该文件有变化.
这可能吗?
我找到了一种方法,git不会要求你藏匿,而是默默地删除你认为在.gitignore中安全的文件.即使您在初始提交后拥有相同的忽略文件,也是如此.
当您在提交中删除了所述文件但在.gitignore中列出然后您签出另一个存在的提交时,会发生此问题:
git init
mkdir ignored/
echo stuff > ignored/file
echo otherstuff > otherfile
git add -A
# Opps added my ignored folders files
# Forgeting to rm --cache
echo ignored/ > .gitignore ; git add .gitignore
git commit -m 'accidentally add ignored/file'
git status
touch dummyfile; git add dummyfile
# Remembered to rm --cache
git rm --cache -rf ignored/file #This file is now vulnerable to clobber
git commit -m 'add stuff'
echo somechange >> ignored/file
## Wait for it.. …Run Code Online (Sandbox Code Playgroud) 我想更改跟踪文件以进行开发,但保持跟踪版本不变.
对此的大多数"解决方案"表明
git update-index --assume-unchanged
Run Code Online (Sandbox Code Playgroud)
但它完全没用,因为文件仍然会被结帐或重置更改.是否有更好的解决方案可以在结账和重置命令后继续存在?
我的git repo master和production有两个分支.主要区别在于生产中,供应商目录已经签入并且不存在于.gitignore中
我的问题是当我从生产切换到掌握时
git checkout master
Run Code Online (Sandbox Code Playgroud)
整个供应商目录被淘汰.
我有什么选择?
让我们看看.gitignore文件 - 我添加了mllib/pom.xml和pom.xml甚至.gitignore(这不应该是必需的 - 所以有些不对劲......):
$head .gitignore
.gitignore
mllib/pom.xml
pom.xml
Run Code Online (Sandbox Code Playgroud)
那么让我们看看git想要添加的文件:
$ 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: .gitignore
modified: mllib/pom.xml
modified:
Run Code Online (Sandbox Code Playgroud)
更新有两条评论不是"忽略.gitignore".但是在再次移除.gitignore之后我们得到了这个:
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: .gitignore
modified: mllib/pom.xml
Run Code Online (Sandbox Code Playgroud)
所以(a).gitignore正在出现,(b)真正重要的不添加到提交的特定文件 - mllib/pom.xml …