推后Github文件删除 [英] Github file removal after push

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

问题描述

我意外地将一个文件推送到了我的Github存储库,并且我试图了解它在哪里。



我已经在这里看过很多文章,但没有人有解决方案,所以我想问一下。



我的步骤如下:

$ g $ g $ g $ g $ g $ g $ git add normal_file.txt $ b $ git add sensitive_content_file.txt
git rm --cached sensitive_content_file.txt
#当时我意识到我添加了一个错误的文件,需要删除它。
git commit -m新变化
git push

我看到它将normal_file.txt推入我的存储库,但是我没有在我的目录中看到sensitive_content_file.txt存储库,所以我认为它不被推送?所以,一切都好?



我试图清理缓存,但现在我的存储库抱怨为:

 您的分支和'origin / master'已经分开,并且分别有1个和1个不同的提交。 

然而,我没有对自己做任何修改。



如何清除与此文件的每个连接,然后尝试删除其缓存? $ c> git rm --cached sensitive_content_file.txt 在提交之前足以将其推送到GitHub。



但现在,它会最好将该文件添加到.gitignore中,以确保不会再错误地添加它:

  echo sensitive_content_file .txt>> .gitignore 
git add .gitignore
git commit -mIngore sensitive_content_file.txt
git push

如果您进行了任何rebase / commit --amend,那将会改变本地历史记录与所推送的内容相比。
如果您还没有完成任何操作本地修改, git reset --hard origin / master 会重置master,然后您可以修改.gitignore并推送。


I accidentally pushed a file to my Github repository, and I am trying to understand where it is.

I have read many posts in here, but none of them had the solution, so I wanted to ask.

My steps were:

git status
git add normal_file.txt
git add sensitive_content_file.txt
git rm --cached sensitive_content_file.txt
#It was the time that I realized I have added a wrong file and need to remove it.
git commit -m "new changes"
git push

I saw that it pushed the "normal_file.txt " into my repository however I have not seen the "sensitive_content_file.txt" in my repository, so I assume it is not being pushed? So that all is okay?

I have tried to clean cache but now my repository complains as:

" Your branch and 'origin/master' have diverged, and have 1 and 1 different commit each, respectively."

However, I did not do any changes to itself.

How can I clear every connection to this file with I tried to remove its caches?

解决方案

git rm --cached sensitive_content_file.txt before the commit was enough to not pushing it to GitHub.

But now, it would be best to add that file to your .gitignore, in order to be sure to not add it again by mistake:

echo sensitive_content_file.txt>>.gitignore
git add .gitignore
git commit -m "Ingore sensitive_content_file.txt"
git push

If you did any rebase/commit --amend, that would change the local history compared to what was pushed.
If you have not done any local modification, a git reset --hard origin/master would reset master, then you can modify the .gitignore and push.

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

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