2013-02-17 58 views
0

我最近在https://github.com/me/myRepo上添加了一个回购。 然后本地(在我的电脑上)我删除了一个文件rm ~/myDir/myFile 我现在想让它在github上消失而没有成功。我所做的:如何删除github上的文件(远程)

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

但文件仍然存在......

当我做

git commit -a 
git push 

这不是工作,我得到

[email protected]:~/.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") 
[email protected]:~/.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. 
+0

正如错误消息所述,您的推送被拒绝。先做一个'git pull'。 – tobiasbayer 2013-02-17 12:53:00

+0

工作!感谢队友,我会尽快接受 – statquant 2013-02-17 12:55:01

回答

3

你必须推送前删除:

rm file 
git commit -a 
git push 
+0

'git commit -a'通常是一个不好的建议.... – ThiefMaster 2013-02-17 12:48:04

+0

您的声明的任何参考? – tobiasbayer 2013-02-17 12:49:55

+0

除删除之外,他可能还有其他未提交的更改。他可能不想同时承诺。 – ThiefMaster 2013-02-17 12:50:40

1

您错过了提交更改。

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

如果你说你想从所有GitHub上,read this历史删除该文件。否则,是的,像其他人所说的那样承诺改变。

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

为了能够使用像过滤器分支选项,你应该总是在存储库中创建,在代码,并承诺,自己的分公司。