Git从我当地项目中不再存在的仓库中删除特定文件夹

时间:2016-07-22 09:55:17

标签: git github version-control bitbucket

我想删除 bitbucket存储库中的特定文件夹,该文件夹在我的本地项目文件夹中不再存在。

我不想使用 git commit -a 提交所有内容,因为我仍在处理某些事情,我不想提交它但我也忽略了很多文件/文件夹并且不确定是否所有内容都包含在.gitignore中(由于大小而我只提交项目的一部分..)。

因此,我只想定位特定文件夹并将其从我的仓库中删除,而不是暂时提交所有内容。我是一个git初学者..它必须是一些我不知道的简单解决方案,问题可以在某处找到,但找不到任何好处......或者我做错了什么。

有什么建议吗?

1 个答案:

答案 0 :(得分:1)

你的问题清楚地表明,你是新手,但没问题:)

注1:你应该提交。您的提交只会出现在本地存储库中,而不会出现在bitbucket上。你可以在推到原点之前修改它。

注意2:您可能应该学会在git上使用分支。它们重量轻且易于使用 - 它可以让您轻松切换工作环境。

注3:您可以使用git stash,但我觉得提交您的工作可能会更好。

所以我的答案是:

$ git checkout -b my-temporary-branch # create local branch for your work
$ git add -A # add everything, that you worked on
$ git commit -m "AMEND ME LATER"
$ git fetch
$ git checkout -b temporary-master origin/master # I don't know what you committed
                                                 # to your local master already,
                                                 # that's why we're switching
                                                 # to whatever was pushed to 
                                                 # bitbucket already
$ git rm -rf <directory name>
$ git commit -m "Directory removed."
$ git push origin master # publish your changes to bitbucket
$ git checkout my-temporary-branch # back to branch
$ git branch -D temporary-master # remove unnecessary branch

然后继续你的工作;您可以使用

修复上次提交
$ git commit --amend

请注意,在将新工作推回到master之前,您需要在origin / master中的更改之前进行合并或变基。