问题描述
我意外地将一个文件推送到了我的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
我看到它将 $ 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文件删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!