如何从Github存储库中删除文件夹?

时间:2015-08-25 18:54:41

标签: git

我按照给出的步骤回答了以下问题:How to remove a directory from git repository?

但是当我执行时(3个中的最后一个命令)

  

git push origin master

我收到以下错误(即使在没有--force的情况下尝试推送文件/文件夹时我也无法解决):

 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'https://github.com/dragGH102/leaderboard-meteor.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

我试过

  

git pull origin master

但它打开了一个CLI接口,我不知道如何进行交互(我在Linux上)。

如何解决此问题?

编辑_完整的shell内容:

git rm -r .meteor
> git commit -m "Remove extra directory"

[master e901990] Remove extra directory
 1 file changed, 10 insertions(+), 1 deletion(-)
> git push origin master

Username for 'https://github.com': dragGH102
Password for 'https://dragGH102@github.com': 
To https://github.com/dragGH102/leaderboard-meteor.git
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/dragGH102/leaderboard-meteor.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

> git pull origin master

# open GUI (no idea how to interact here and what to do)
Merge branch 'master' of https://github.com/dragGH102/leaderboard-meteor

# Please enter a commit message to explain why this merge is necessary,
# especially if it merges an updated upstream into a topic branch.
#
# Lines starting with '#' will be ignored, and an empty message aborts
# the commit.
                              [ line 1/8 (12%), col 1/73 (1%), char 0/300 (0%) ]
^G Get Help       ^O WriteOut       ^R Read File      ^Y Prev Page      ^K Cut Text       ^C Cur Pos
^X Exit           ^J Justify        ^W Where Is       ^V Next Page      ^U UnCut Text     ^T To Spell

2 个答案:

答案 0 :(得分:2)

这将从git和本地

中删除目录
git rm -r the_directory
git commit -m "Remove duplicated directory"
git push origin master

仅从git中删除

git rm -r --cached folder_name

答案 1 :(得分:1)

git pull包括合并,这正是您所面临的问题。如果上游没有变化,则会有快进合并

  

当前分支头通常是命名提交的祖先。这个   是最常见的情况,特别是从git pull调用时:你是   跟踪上游存储库,您没有提交本地更改,   现在您想要更新到更新的上游版本。在这种情况下,   存储组合历史不需要新的提交;相反,   HEAD(以及索引)更新为指向命名提交,   无需创建额外的合并提交。

但是,由于您的回购和上游都已更改,您将面临真正的合并

  

合并版本协调所有分支的更改   已提交merged,您的HEAD,索引和工作树都是   更新到它。可以对工作进行修改   树只要它们不重叠;更新将保留它们。

由于没有冲突,您只需键入提交消息即可完成合并。

报价来源:https://www.kernel.org/pub/software/scm/git/docs/git-merge.html

更多信息:https://git-scm.com/book/en/v2/Git-Branching-Basic-Branching-and-Merging