将所有删除的文件添加到带有git的提交

发布于 2025-02-13 23:59:07 字数 279 浏览 4 评论 0原文

我已经对分支机构进行了一轮更改,并有10个修改后的文件和10个文件。

如果我运行git add。这只会将修改的文件添加到我的提交中。我想从远程存储库中删除已删除的文件,并添加我的修改后的文件。

我可以使用git rm fileName,但是由于我有很多文件可以删除,所以我想知道是否有一种“全部”的方法。

我谷歌搜索并找到了git rm -r *,但这似乎不起作用。

有没有命令可以让我这样做?

I have made a round of changes to a branch and have 10 modified files and 10 files I have deleted.

If I run git add . this will only add the modified files to my commit. I want to remove the deleted files from the remote repo as well as add my modified files.

I can use git rm filename, but since I have so many files to remove I was wondering if there was a way to do an 'all'.

I Googled and found git rm -r * but this doesn't seem to work.

Is there a command that will allow me to do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(7

古镇旧梦 2025-02-20 23:59:07

如果您想进行所有更改和删除的文件并单行提交:

git commit -am "changing and deleting files"

请注意,该命令不会添加新文件,因为GIT是关于跟踪更改的。它依靠您告诉它哪些文件足够重要,可以跟踪。
如果您有一些或只想在提交之前进行更改,则必须手动添加文件或使用通配符:

  • git git add -a stage ast as all(包括新文件,修改和删除)
  • git add。阶段新的和修改,没有删除
  • git add -u阶段修改和删除,

而没有新的commit:

git commit -m "..."

If you want to stage all your changed and deleted files and commit in one-line:

git commit -am "changing and deleting files"

Note that this command won't add new files as Git is about tracking changes. It relies on you to tell it which files are important enough to track.
If you have some or you just want to stage the changes before you commit, you will have to add your files manually or use wildcard:

  • git add -A stages All (include new files, modified and deleted)
  • git add . stages new and modified, without deleted
  • git add -u stages modified and deleted, without new

then commit:

git commit -m "..."
柳絮泡泡 2025-02-20 23:59:07

尝试以下操作:

git add -u为包括已删除/更新文件在内的所有更改。

然后只需运行git commit -m'您的提交消息'进行提交即可。

Try this:

git add -u to stage all your changes including deleted/updated files.

Then just run git commit -m 'your commit message' to commit.

嘴硬脾气大 2025-02-20 23:59:07

使用Interactive git add,它允许交互方式选择文件:

  1. 键入git add -i
  2. 键入2(更新部分)。
  3. 类型应删除的文件号。您可以使用范围一次选择多个文件,例如1-10

https://git-scm.com/book/book/en/v2 /git-tools-interactive阶段

Use interactive git add, it allows to select files interactively:

  1. Type git add -i.
  2. Type 2 (update section).
  3. Type file numbers which should be deleted. You can use ranges to select multiple files at once, like 1-10.

https://git-scm.com/book/en/v2/Git-Tools-Interactive-Staging

掩耳倾听 2025-02-20 23:59:07

可以使用标准外壳工具。在这种情况下> ripgrep )。

建议的命令是:

git status | grep <state> | awk -F ':' '{print $2}' | xargs git add

# or
git status | grep <state> | awk -F ':' '{print $2}' | xargs git commit -m "<msg>"

# for deleted files only:
git status | grep deleted | awk -F ':' '{print $2}' | git commit -m "<msg>"

如果您知道每个工具,则命令大多是自我解释的。如果您不这样做,请学习它们,它们很有用。简而言之:GREP找到具有指定状态的行。 “删除”。尴尬过滤第二列。 Xargs将其转换为参数格式。

为此/这些管道制造一个别名使它成为一项琐碎的任务。

It is possible to utilize standard shell tools. In this case grep, xargs and awk (or their newer/faster/different alternatives like nawk or ripgrep).

The suggested command is:

git status | grep <state> | awk -F ':' '{print $2}' | xargs git add

# or
git status | grep <state> | awk -F ':' '{print $2}' | xargs git commit -m "<msg>"

# for deleted files only:
git status | grep deleted | awk -F ':' '{print $2}' | git commit -m "<msg>"

The command is mostly self-explonatory if you know each tool. If you dont, learn them, they are usefull. In short: grep finds lines with specified status eg. "deleted". awk filters second column. xargs transforms it to argument format.

Making an alias for this/these pipeline makes it a trivial task.

清旖 2025-02-20 23:59:07

git rm -r *您需要提交文件并推动后,您将看到

git add . 
git commit -m 'Remove all files'
git push

可以帮助您的更改希望:)

After the git rm -r * you need to commit your file and push and you gonna see the change

git add . 
git commit -m 'Remove all files'
git push

Hope that can help you :)

不回头走下去 2025-02-20 23:59:07

要将删除的文件添加到git索引,请运行

git add --all .

To add removed files to the the git index, run

git add --all .
冷︶言冷语的世界 2025-02-20 23:59:07

要影响远程服务器中的更改,您需要在push从远程服务器上进行更改。

git add。要跟踪所有更改

git commit -m“您的消息” cistion

git push push oincor [your -branch]以将更改推到 现在,您的远程存储库

通过ssh'将这些更改拉到您的远程服务器上,然后导航到项目路径,

git pull origin [your-branch]

然后将文件从远程服务器中删除

To affect the changes in remote server you need to both push changes from your local machine and pull from remote server.

git add . to track all changes

git commit -m "your message" to commit

git push origin [your-branch] to push changes to your remote repo

Now pull those changes to your remote server by ssh'ing to it and navigating to project path and do

git pull origin [your-branch]

Then the files would be deleted from your remote server

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