使用 git 将所有删除的文件添加到提交中

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/41497031/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 12:32:10  来源:igfitidea点击:

Add all removed files to a commit with git

git

提问by MeltingDog

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

我对一个分支进行了一轮更改,并删除了 10 个修改文件和 10 个文件。

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.

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

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'.

我可以使用git rm filename,但由于我有太多文件要删除,我想知道是否有办法做到“全部”。

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

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

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

是否有允许我执行此操作的命令?

回答by ET-CS

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 是关于跟踪更改的。它依赖于您告诉它哪些文件足够重要以进行跟踪。如果您有一些或只想在提交之前暂存更改,则必须手动添加文件或使用通配符:

  • git add -Astages All (include new files, modified and deleted)
  • git add .stages new and modified, without deleted
  • git add -ustages modified and deleted, without new
  • git add -A阶段所有(包括新文件,修改和删除)
  • git add .新的和修改的阶段,没有删除
  • git add -u修改和删除的阶段,没有新的

then commit:

然后提交:

git commit -m "..."

回答by Alex Pan

Try this:

尝试这个:

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

git add -u暂存您的所有更改,包括已删除/更新的文件。

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

然后只需运行git commit -m 'your commit message'即可提交。

回答by Harald Nordgren

To add removed files to the the git index, run

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

git add --all .

回答by EQuimper

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

git rm -r *您需要提交文件并推送之后,您将看到更改

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

Hope that can help you :)

希望能帮到你 :)

回答by Gayan

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

要影响远程服务器的更改,您需要push从本地计算机和pull远程服务器进行更改。

git add .to track all changes

git add .跟踪所有更改

git commit -m "your message"to commit

git commit -m "your message"承诺

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

git push origin [your-branch]将更改推送到您的远程仓库

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

现在将这些更改拉到您的远程服务器ssh上,然后导航到项目路径并执行

git pull origin [your-branch]

Then the files would be deleted from your remote server

然后这些文件将从您的远程服务器中删除