如何删除 git 存储库中的所有文件并从本地 git 存储库更新/推送?

发布于 2024-12-29 17:48:06 字数 141 浏览 4 评论 0原文

是否可以删除存储库中的所有文件并仅使用本地计算机中的文件进行更新?原因是,我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(15

素手挽清风 2025-01-05 17:48:06

你可以这样做:

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

可能有一个单线......

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…

泪之魂 2025-01-05 17:48:06

首先,使用以下命令从 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)

娇女薄笑 2025-01-05 17:48:06

是的,如果您执行 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.

哽咽笑 2025-01-05 17:48:06

警告:这将删除您的文件,请确保您有备份或可以恢复提交。

删除存储库中的所有元素:

$ git rm -r *

然后:

$ git commit -m 'Delete all the stuff'

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'
对你再特殊 2025-01-05 17:48:06

就我而言,

git rm -r .

完成了这项工作

In my case

git rm -r .

made the job

老旧海报 2025-01-05 17:48:06

首先,使用 cd (更改目录)命令导航到您的文件夹。 请使用命令确保您位于想要工作的正确 git 分支中

git branch

然后,如果您想删除整个文件, 。您可以使用

git rm -r .

来删除单个文件,

使用 git rm file1.txt ( file1.txt - 文件名 )

来删除文件夹,

git rm -rfoldername

删除文件或文件夹后,您应该提交它:

git commit -m "your comment"

然后您可以推送分支:(

git push
// for example, 
git push origin develop

它将更新原始存储库)

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

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:

git commit -m "your comment"

Then you can push the branch:

git push
// for example, 
git push origin develop

(it will update the origin repository)

太阳公公是暖光 2025-01-05 17:48:06

这个过程很简单,并且遵循与任何 git 提交相同的流程。

  1. 确保您的存储库完全是最新的。 (例如:git pull
  2. 导航到本地磁盘上的存储库文件夹。
  3. 删除您不再需要的文件。
  4. 然后git commit -m“nuke并重新开始”
  5. 然后git push
  6. 获利。

This process is simple, and follows the same flow as any git commit.

  1. Make sure your repo is fully up to date. (ex: git pull)
  2. Navigate to your repo folder on your local disk.
  3. Delete the files you don't want anymore.
  4. Then git commit -m "nuke and start again"
  5. Then git push
  6. Profit.
终弃我 2025-01-05 17:48:06

我试图这样做:

git rm -r *

但最终对我来说有效:

git rm -r .

我希望它对你有帮助。

I was trying to do :

git rm -r *

but at the end for me works :

git rm -r .

I hope it helps to you.

刘备忘录 2025-01-05 17:48:06

只需运行它,就为我解决了:

git rm -r --cached .
git add .
git commit -m "remove gitignore files"
git push

如此处回答:
https://stackoverflow.com/a/50675909/3294762

Just running it, solved for me:

git rm -r --cached .
git add .
git commit -m "remove gitignore files"
git push

as answered here:
https://stackoverflow.com/a/50675909/3294762

揽清风入怀 2025-01-05 17:48:06

从工作副本顶部执行 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 at git status and/or git diff --cached to review what you're about to do, then git commit the result.

柳絮泡泡 2025-01-05 17:48:06

如果您更喜欢使用 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.

樱娆 2025-01-05 17:48:06

我已经尝试过这样

git rm --cached -r * -f

并且它对我有用。

I have tried like this

git rm --cached -r * -f

And it is working for me.

梦醒灬来后我 2025-01-05 17:48:06

删除存储库中的所有元素:

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"

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"
兔姬 2025-01-05 17:48:06

删除所有不属于存储库的文件(例如,切换分支后进行全新构建):

 git status | xargs rm -rf

Remove all files not belonging to a repositiory (e.g. for a clean-build after switching a branch):

 git status | xargs rm -rf
回忆凄美了谁 2025-01-05 17:48:06

删除隐藏的 .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 using git init command.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文