简体   繁体   English

如何删除github上的文件(远程)

[英]how to delete a file on github (remote)

I recently added a repo on https://github.com/me/myRepo . 我最近在https://github.com/me/myRepo上添加了一个仓库。 Then locally (on my computer) I removed a file rm ~/myDir/myFile I am trying now to make it disappear on github without success. 然后在本地(在我的计算机上)删除了一个文件rm ~/myDir/myFile我现在尝试使其消失在github上而没有成功。 I did: 我做了:

cd ~/myDir
git rm myFile (I had already remove the file physically)
git add -A
git push

But the file is still there... 但是文件仍然在那里...

When I do 当我做

git commit -a
git push

This is not working, I get 这不起作用,我明白了

statquant@euclide:~/.vim$ git commit -a
# On branch master
# Your branch is ahead of 'origin/master' by 1 commit.
#
# 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)
#   (commit or discard the untracked or modified content in submodules)
#
#   modified:   bundle/Align (untracked content)
#   modified:   bundle/Clang_Complete-Pathogen (untracked content)
#   modified:   bundle/Vim-R-plugin (untracked content)
#   modified:   bundle/bash-support.vim (untracked content)
#   modified:   bundle/git (untracked content)
#   modified:   bundle/nerdtree (untracked content)
#   modified:   bundle/perl-support.vim (untracked content)
#   modified:   bundle/snipmate (modified content, untracked content)
#   modified:   bundle/tasklist (modified content)
#
no changes added to commit (use "git add" and/or "git commit -a")
statquant@euclide:~/.vim$ git push
To https://github.com/statquant/.vim.git
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/statquant/.vim.git'
To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes (e.g. 'git pull') before pushing again.  See the
'Note about fast-forwards' section of 'git push --help' for details.

You have to commit the deletion before pushing: 您必须先提交删除操作,然后再进行以下操作:

rm file
git commit -a
git push

You are missing to commit the changes. 您缺少提交更改。

$ cd ~/myDir
$ git rm myFile
$ git commit -a -m "Your commit message"
$ git push origin master

If you're saying that you want to remove the file from all of the history on github, read this . 如果您要从github上的所有历史记录中删除文件, 请阅读this Otherwise, yeah commit the change like everyone else has said. 否则,像其他所有人一样,提交更改。

git rm <file>

git commit -m "deleted a file"

git push

However, the file is still available through the history, eg through a cherry-pick of the commit that put it in the repository in the first place. 但是,该文件在整个历史记录中仍然可用,例如,通过首先将其放入存储库中的提交进行挑选。

For sensitive data, or perhaps code you want to ensure never ever makes its way back into your project, it is recommended to 'rewrite' an entire branch's commit history with git filter-branch . 对于敏感数据,或者您想确保永远不会回到项目中的代码,建议使用git filter-branch '重写'整个分支的提交历史记录。

WARNING: this will change the SHA-1 hash of ALL the commits in the branch from the point the (now removed) file was originally added, so you will not be able to easily push and distribute the rewritten branch on top of the original branch. 警告:这将从原始添加(现已删除)文件的位置更改分支中所有提交的SHA-1哈希,因此您将无法轻松地将重写的分支推入并分发到原始分支的顶部。 If it is a very recent commit you are removing, then this approach may not cause a problem for others. 如果您要删除的是最近的提交,则此方法可能不会对其他人造成问题。

git filter-branch --index-filter 'git rm --cached --ignore-unmatch <file>' HEAD

To be able to use options like filter-branch, you should always create, code in, and commit to, your own branch within a repository. 为了能够使用filter-branch之类的选项,您应该始终在存储库中创建,编码并提交到自己的分支。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM