如何删除我的 git repo 中的所有文件并从我的本地 git repo 更新/推送?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9050914/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I remove all files in my git repo and update/push from my local git repo?
提问by dchhetri
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.
是否可以删除存储库中的所有文件并仅使用本地计算机中的文件更新它?原因是,我的 github 中有些文件不是必需的,所以我想删除这些文件。我不是一个一个地删除文件,而是想看看是否可以只删除我的 git repo 中的所有文件,并仅使用本地机器中的文件进行更新/推送。希望它清楚。谢谢。
采纳答案by First Zero
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.
是的,如果您执行git rm <filename>
并提交并推送这些更改。该文件将从该变更集和未来提交的存储库中消失。
The file will still be available for the previous revisions.
该文件仍可用于以前的修订版。
回答by pascal
You could do it like this:
你可以这样做:
cd /tmp
git clone /your/local/rep # make a temp copy
cd rep
git rm -r * # delete everything
cp -r /your/local/rep/* . # get only the files you want
git add * # add them again
git status # everything but those copied will be removed
git commit -a -m 'deleting stuff'
cd /your/local/rep
git pull /tmp/rep # now everything else has been removed
There's probably a oneliner for that…
可能有一个oneliner...
回答by Mohamed Taboubi
First, remove all files from your Git repository using: git rm -r *
首先,使用以下命令从 Git 存储库中删除所有文件: git rm -r *
After that you should commit: using git commit -m "your comment"
之后你应该提交:使用 git commit -m "your comment"
After that you push using: git push
(that's update the origin repository)
之后你使用:(git push
即更新源存储库)
To verify your status using: git status
使用以下方法验证您的状态: 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
之后,您可以复制本地 Git 文件夹中的所有本地文件,并使用以下命令将它们添加到 Git 存储库: git add -A
You commit (git commit -m "your comment"
and you push (git push
)
你提交 (git commit -m "your comment"
并且你推 ( git push
)
回答by Jorgesys
Warning: this will delete your files, make sure you have a backup or can revert the commit.
警告:这将删除您的文件,请确保您有备份或可以还原提交。
Delete all elements in repository:
删除存储库中的所有元素:
$ git rm -r *
then:
然后:
$ git commit -m 'Delete all the stuff'
回答by HoCo_
In my case
就我而言
git rm -r .
git rm -r .
made the job
完成了工作
回答by pimbrouwers
This process is simple, and follows the same flow as any git commit.
这个过程很简单,并且遵循与任何 git commit 相同的流程。
- Make sure your repo is fully up to date. (ex:
git pull
) - Navigate to your repo folder on your local disk.
- Delete the files you don't want anymore.
- Then
git commit -m "nuke and start again"
- Then
git push
- Profit.
- 确保您的回购完全是最新的。(例如:
git pull
) - 导航到本地磁盘上的 repo 文件夹。
- 删除不再需要的文件。
- 然后
git commit -m "nuke and start again"
- 然后
git push
- 利润。
回答by Varun P V
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 git branch.
首先,使用cd(更改目录)命令导航到您的文件夹。然后使用命令git branch确保您处于要工作的正确 git 分支中。
If you want to delete the entire files. you can do the same by using git rm -r .
如果要删除整个文件。你可以使用git rm -r来做同样的事情。
for deleting a single file, git rm file1.txt( file1.txt - file Name )
删除单个文件,git rm file1.txt( file1.txt - file Name )
for delete a folder, git rm -r foldername
删除文件夹,git rm -r foldername
After deleting the files or folders, you should commit it: git commit -m "your comment"
删除文件或文件夹后,您应该提交它:git commit -m "your comment"
Then you can push the branch: git pushfor example, git push origin develop(it will update the origin repository)
然后你可以推送分支:git push例如,git push origin develop(它会更新origin存储库)
回答by Luis Miguel Ramos
I was trying to do :
我试图做:
git rm -r *
but at the end for me works :
但最后对我来说是有效的:
git rm -r .
I hope it helps to you.
我希望它对你有帮助。
回答by Borealid
Do a git add -A
from the top of the working copy, take a look at git status
and/or git diff --cached
to review what you're about to do, then git commit
the result.
做一个git add -A
从工作拷贝顶部,看看git status
和/或git diff --cached
你怎么样去做,那么git commit
结果。
回答by Akash Kandpal
Delete all elements in repository:
删除存储库中的所有元素:
git rm -r * -f -q
then:
然后:
git commit -m 'Delete all the stuff'
then:
然后:
git push -u origin master
then:
然后:
Username for : "Your Username"
Password for : "Your Password"