2013-02-17 55 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

爲了能夠使用像過濾器分支選項,你應該總是在存儲庫中創建,在代碼,並承諾,自己的分公司。