如何删除 git 存储库中的所有文件并从本地 git 存储库更新/推送?
是否可以删除存储库中的所有文件并仅使用本地计算机中的文件进行更新?原因是,我的 github 中有一些不需要的文件,所以我想删除这些文件。我不想一一删除文件,而是想看看是否可以删除 git 存储库中的所有文件并仅使用本地计算机中的文件进行更新/推送。希望它清楚。谢谢。
Is it possible to remove all files in a repository and update it with only the files I have in my local machine? The reason is that, there are certain files that is not necessary in my github and so I want to remove those files. Instead of removing the files one by one, I wanted to see if its possible to just remove all files in my git repo and update/push with only the files in my local machine. Hope its clear. Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(15)
你可以这样做:
可能有一个单线......
You could do it like this:
There's probably a oneliner for that…
首先,使用以下命令从 Git 存储库中删除所有文件:
git rm -r *
之后您应该提交:使用
git commit -m "your comment"
之后使用:
git push
(即更新原始存储库)使用:
git status
验证您的状态之后,您可以将所有本地文件复制到本地Git文件夹中,然后添加使用以下命令将它们添加到 Git 存储库:
git add -A
提交 (
git commit -m "your comment"
并推送 (git Push
)First, remove all files from your Git repository using:
git rm -r *
After that you should commit: using
git commit -m "your comment"
After that you push using:
git push
(that's update the origin repository)To verify your status using:
git status
After that you can copy all your local files in the local Git folder, and you add them to the Git repository using:
git add -A
You commit (
git commit -m "your comment"
and you push (git push
)是的,如果您执行
git rm
并提交 &推动这些改变。该文件将从该变更集和未来提交的存储库中消失。该文件仍可用于以前的修订。
Yes, if you do a
git rm <filename>
and commit & push those changes. The file will disappear from the repository for that changeset and future commits.The file will still be available for the previous revisions.
警告:这将删除您的文件,请确保您有备份或可以恢复提交。
删除存储库中的所有元素:
然后:
Warning: this will delete your files, make sure you have a backup or can revert the commit.
Delete all elements in repository:
then:
就我而言,
git rm -r .
完成了这项工作
In my case
git rm -r .
made the job
首先,使用 cd (更改目录)命令导航到您的文件夹。 请使用命令确保您位于想要工作的正确 git 分支中
然后,如果您想删除整个文件, 。您可以使用
git rm -r .
来删除单个文件,
使用 git rm file1.txt ( file1.txt - 文件名 )
来删除文件夹,
git rm -rfoldername
删除文件或文件夹后,您应该提交它:
然后您可以推送分支:(
它将更新原始存储库)
First of all, Navigate to your Folder using cd ( change directory) command. Then make sure you are in the correct git branch which you want to work by using the command
If you want to delete the entire files. you can do the same by using
git rm -r .
for deleting a single file,
git rm file1.txt
( file1.txt - file Name )for delete a folder,
git rm -r foldername
After deleting the files or folders, you should commit it:
Then you can push the branch:
(it will update the origin repository)
这个过程很简单,并且遵循与任何 git 提交相同的流程。
git pull
)git commit -m“nuke并重新开始”
git push
This process is simple, and follows the same flow as any git commit.
git pull
)git commit -m "nuke and start again"
git push
我试图这样做:
但最终对我来说有效:
我希望它对你有帮助。
I was trying to do :
but at the end for me works :
I hope it helps to you.
只需运行它,就为我解决了:
如此处回答:
https://stackoverflow.com/a/50675909/3294762
Just running it, solved for me:
as answered here:
https://stackoverflow.com/a/50675909/3294762
从工作副本顶部执行 git add -A ,查看 git status 和/或 git diff --cached 来检查您将要执行的操作,然后
git commit
结果。Do a
git add -A
from the top of the working copy, take a look atgit status
and/orgit diff --cached
to review what you're about to do, thengit commit
the result.如果您更喜欢使用 GitHub Desktop,您只需导航到本地存储库的父目录并删除所有父目录中的文件。然后,提交并推送您的更改。您的存储库中的所有文件都将被清除。
If you prefer using GitHub Desktop, you can simply navigate inside the parent directory of your local repository and delete all of the files inside the parent directory. Then, commit and push your changes. Your repository will be cleansed of all files.
我已经尝试过这样
并且它对我有用。
I have tried like this
And it is working for me.
删除存储库中的所有元素:
then:
then:
then:
Delete all elements in repository:
then:
then:
then:
删除所有不属于存储库的文件(例如,切换分支后进行全新构建):
Remove all files not belonging to a repositiory (e.g. for a clean-build after switching a branch):
删除隐藏的 .git 文件夹(您可以在项目文件夹中找到该文件夹),然后再次使用 git init 命令开始创建 git 存储库的过程。
Delete the hidden
.git
folder (that you can locate within your project folder) and again start the process of creating a git repository usinggit init
command.