且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

更新git仓库时删除已删除的文件/文件夹

更新时间:2023-12-04 20:23:04

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.