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

时间:2013-02-17 12:46:13

标签: git github

我最近在https://github.com/me/myRepo添加了一个回购。 然后在本地(在我的计算机上)我删除了一个文件rm ~/myDir/myFile 我现在正试图让它在github上消失而没有成功。我做了:

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

但文件还在那里......

当我这样做时

git commit -a
git push

这不起作用,我得

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.

4 个答案:

答案 0 :(得分:3)

你必须在推送之前提交删除:

rm file
git commit -a
git push

答案 1 :(得分:1)

您缺少提交更改。

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

答案 2 :(得分:0)

如果您要删除github上read this的所有历史记录中的文件。否则,是的,就像其他人所说的一样,做出改变。

答案 3 :(得分:0)

git rm <file>

git commit -m "deleted a file"

git push

但是,该文件仍可通过历史记录获得,例如通过一个樱桃选择,它首先将它放入存储库中。

对于敏感数据,或者您希望确保永远不会重新进入项目的代码,建议您重写&#39;整个分支的git filter-branch提交历史记录。

警告:这将从最初添加(现在删除)文件的位置更改分支中所有提交的SHA-1哈希值,因此您将无法轻松地推送和分发重写的分支。原来的分支。如果这是你最近要删除的提交,那么这种方法可能不会给其他人带来问题。

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

为了能够使用filter-branch之类的选项,您应该始终在存储库中创建,编码和提交您自己的分支。