0

我最近在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

4 回答 4

3

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

rm file
git commit -a
git push
于 2013-02-17T12:47:48.040 回答
1

您缺少提交更改。

$ cd ~/myDir
$ git rm myFile
$ git commit -a -m "Your commit message"
$ git push origin master
于 2013-02-17T12:48:22.190 回答
0

如果您说要从 github 上的所有历史记录中删除该文件,请阅读此. 否则,是的,像其他人所说的那样进行更改。

于 2013-02-17T12:48:40.197 回答
0

git rm <file>

git commit -m "deleted a file"

git push

但是,该文件仍然可以通过历史记录获得,例如,通过对首先将其放入存储库的提交进行挑选。

对于敏感数据,或者您希望确保永远不会重新进入项目的代码,建议使用git filter-branch.

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

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

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

于 2014-06-20T14:22:35.220 回答