更新git仓库时删除已删除的文件/文件夹 [英] Delete deleted files/folder when updating a git repo

查看:636
本文介绍了更新git仓库时删除已删除的文件/文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个git repo并提交了文件/文件夹,经过一段时间从我的本地git文件夹中删除了一个文件夹,并试图更新repo我运行命令 -

  git add。 
git commit -m第二次提交
git remote add origin https://github.com/trialcode/test.git
git push -u原始大师

但删除的文件夹仍然显示在我的git repo中,但文件已更新。



仅供参考 - 我试过 git分支-d folder_to_remove /
但它引发错误 - 错误:branch'folder_to_remove /'not found

解决方案

Git将在本地repo目录中有一个隐藏文件夹 .git / 。所有有关本地存储库的信息都将存储在该文件夹中。



因此,当您创建文件夹并提交时,它将被存储。之后,即使删除文件或你的文件系统中的文件夹将不会被通知到本地git仓库。



要通知git您已经删除了文件或文件夹,请使用命令

  git rm folder_name 
git commit -m已删除的文件夹
git远程添加源https://github.com/trialcode/test.git
git push -u原始大师

这里 folder_name 是您希望的文件名或文件夹名称删除。


I created a git repo and commited files/folder, after some time a deleted a folder from my local git folder and in try to update the repo I run the commands -

git add .
git commit -m "second commit"
git remote add origin https://github.com/trialcode/test.git
git push -u origin master

But the removed folder is still shown there in my git repo although the files were updated. Let me know what I am doing wrong with the git files/folder update.

FYI - I tried git branch -d folder_to_remove/ but it is throwing an error - error: branch 'folder_to_remove/' not found.

解决方案

Git will have a hidden folder .git/ in your local repo directory. Everything about your local repository will be stored inside that folder.

So When You create a folder and commit, it will be stored.After that even if you delete the file or folder from your file system it will not be notified to local git repository.

To notify git that you have deleted a file or folder use the command git rm.

Try this

git rm folder_name
git commit -m "removed folder"
git remote add origin https://github.com/trialcode/test.git
git push -u origin master

Here folder_name is the filename or folder name which you wish to remove.

这篇关于更新git仓库时删除已删除的文件/文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆