我对文件进行了更改后.我用git add FILE_NAME.
然后,我想恢复它,因为没有添加,但同时保持更改,如何做到这一点?
这个问题试图消除关于追溯应用 .gitignore 的混淆,而不仅仅是现在/未来。1
我一直在寻找一种方法来追溯强制执行我当前的 .gitignore ,就像我在第一次提交中创建了 .gitignore 一样。
我正在寻求的解决方案:
*.ext
!*special.ext
Run Code Online (Sandbox Code Playgroud)
git rm --cached *.ext
git commit
Run Code Online (Sandbox Code Playgroud)
这需要 1. 手动指定文件和 2. 附加提交,这将导致在其他开发人员拉取时删除新忽略的文件。(它实际上只是一个git rm- 这是从 git 跟踪中删除- 但它会将文件单独留在本地(您的)工作目录中。 之后其他人git pull将收到文件删除提交)
git filter-branch --index-filter 'git rm --cached *.ext' …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 …
采用最新的git( 2.1.0.24),每当我尝试git rebase -i到squash一些提交,壁球不能detach HEAD状态.我希望它可以压缩提交并按照我的预期把我放回我的分支.没有未暂存的文件,工作树中的更改或存储中的任何内容.它为什么这样做?
> [master] » git rebase -i HEAD~3
Run Code Online (Sandbox Code Playgroud)
(我压制了一些提交)......
pick c9e9b62 Fixes super important bug #123.
squash c0dc9f9 wip
pick 5385a37 wip2
# Rebase fb83e59..5385a37 onto fb83e59
Run Code Online (Sandbox Code Playgroud)
(然后它给了我)
Note: checking out 'c9e9b62'.
You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.
If you …Run Code Online (Sandbox Code Playgroud) 我有node_modules并bower_components在 .gitignore 中。每次我切换分支时,所有依赖项都会被删除(全局安装的依赖项除外),并且我必须重新安装所有依赖项。
我目前正在使用git stash save --keep-index --include-untracked \xe2\x80\x94all,但我想知道是否有一个更简单的解决方案,它可以在从另一个分支切换回来后保留 .gitignore 中的目录。
我正在为Windows 10制作一个客户端应用程序.我有一个问题,我想开源我的代码,但让其他人看不到API密钥.这是我的源文件的相关部分:
private const string ApiKey = "YOUR_API_KEY";
Run Code Online (Sandbox Code Playgroud)
我想把它变成
private const string ApiKey = "THE_ACTUAL_API_KEY";
Run Code Online (Sandbox Code Playgroud)
什么时候编译.我该怎么做呢?
编辑:对不起任何含糊之处; 我问如何防止GitHub上的源代码的查看者看到字符串,而不必在本地构建期间更改它.此问题与加密无关.
我使用以下命令在我的 Xcode 项目中添加了一个 git ignore 文件:touch .gitignore然后open .gitignore将其复制并粘贴到git ignore 内容中(并取消注释该行的Pods/行)并保存文件。
但是当我仍然尝试在 Xcode 中提交(已经提交了很多次)时,Pods 文件仍然存在并且已经检查提交。
如何不检查我的 Pod 文件并使 git ignore 与我的 Xcode 项目一起工作?
我有一个带有本地设置的文件的存储库。我已经将它添加到 .gitignore 和 .git/info/exclude 但它之前被推送到服务器并且 git 想要跟踪它们。
如何排除这个文件?
我有一个文件config-dev.php,它将用作开发版本配置.
现在,另一位开发人员想要在此文件中进行自己的更改.
当他提交时,这个文件被提交,我的config-dev.php被同事的文件覆盖.
这个文件是在.gitignore但它仍然无法正常工作.
如何从git索引中删除此文件,以便每个人都可以拥有自己的config-dev.php?
我试过git rm --cached config-dev.php但它还没有用.这个命令应该由所有同事执行吗?或者我应该在git rm之后同步?
我试图忽略存储库中的所有 .pyc 扩展名,我的 .gitignore 文件如下所示
.idea
*.rdb
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*.pyc
__pycache__/
Run Code Online (Sandbox Code Playgroud)
然而当我这样做的时候git status。我得到有关修改文件的信息,如下所示
On branch master
Your branch is up-to-date with 'origin/master'.
Changes not staged for commit:
(use "git add/rm <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: .DS_Store
modified: .gitignore
modified: Device/__init__.py
modified: Device/admin.py
modified: Device/apps.py
modified: Device/migrations/0001_initial.py
modified: Device/migrations/__init__.py
modified: Employee/__init__.py
modified: Employee/__pycache__/__init__.cpython-35.pyc
Run Code Online (Sandbox Code Playgroud)
请注意,最后一个文件 .pyc 显示为已修改,并且还显示了添加到 .gitignore 的折叠 …