GIT并推送忽略的文件 [英] GIT and pushing with ignored files

查看:72
本文介绍了GIT并推送忽略的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用git必须遵循的确切步骤是什么?我将给出我的程序(以某种方式,它不能很顺利地进行工作):

What is the exact the procedure you have to follow using git? I will give my procedure (which is, somehow, not working very smoothly):

- cloned a repository: (works fine)
- added settings files to .gitignore to prevent overwriting the originial 
    settingfiles on the remote (= test environment)
- made changes to my local repository and committed it locally (works fine)
- pushed it from local to remote (did not work properly)

当推入遥控器时,遥控器上的设置文件被删除,这导致我的测试环境崩溃.我只是希望如果我推送设置文件而不将其删除,则将其忽略.

When pushing to the remote the settingfiles on the remote are deleted, which caused my test envirnment to die. I just want the settings files to be ignored if I push and not deleted.

我做错了什么/忘记了什么?有什么想法吗?

What did I do wrong/forget? Any ideas?

推荐答案

在您克隆的git repo中已经跟踪了settingsfile.这意味着即使将其添加到.gitignore,它仍将被跟踪.

from what i understand, the settingsfile was already tracked in the git repo that you cloned. this means that even if you add it to .gitignore, it will still be tracked.

要从历史记录中删除文件,并确保以后将其忽略

to remove the file from the history, and make sure it's ignored in the future you should

  • 将其添加到.gitignore(就像您已经做过的那样)
  • 运行git filter-branch --index-filter 'git rm --cached --ignore-unmatch settingsfile' HEAD
  • add it to the .gitignore (as you already did)
  • run git filter-branch --index-filter 'git rm --cached --ignore-unmatch settingsfile' HEAD

请注意,您需要为文件所在的每个分支运行以上命令.

note that you need to run the above command for each of the branches where the file is present.

然后您需要git push -f origin master(如果master是分支的名称,而origin是远程的名称)

then you need to git push -f origin master (if master is the name of the branch, and origin the name of the remote)

您可以参考本指南以获取更多信息

you can refer to this guide for additional info.

此外,正如拉菲德·K·阿卜杜拉(Rafid K. Abdullah)所说,您尚未删除任何内容(如果您按照帖子中描述的工作流程进行操作);您刚刚添加了可以轻松还原的修改.毕竟这就是git的目的:)

Also, as Rafid K. Abdullah said, you haven't deleted anything (if you have followed the workflow you describe in your post); you have just added modifications that you can easily revert. that's what git is for after all :)

这篇关于GIT并推送忽略的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆