git add/rm(提交)

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

git add/rm (committing)

git

提问by penguin

So I've taken over a website, some of which has been under git version control (one of the devs used it, the other didn't). So I'm going to commit everything so far, and work from there.

所以我接管了一个网站,其中一些已经在 git 版本控制之下(一个开发人员使用它,另一个没有)。所以我要承诺到目前为止的一切,并从那里开始工作。

However, there are a few files with a git status which I don't quite understand. They are labelled as:

但是,有一些文件的 git 状态我不太明白。它们被标记为:

# Changed but not updated:
#   (use "git add/rm <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)

So if I simply run git commit, will the changes made to these files work their way in to the repository? It's just I don't get why you would do add/rm- seems like adding and then removing all in one foul swoop.

因此,如果我只是运行 git commit,对这些文件所做的更改是否会进入存储库?只是我不明白为什么你会做 add/rm- 看起来像是在一次犯规中添加然后删除所有内容。

Thanks for your help!

谢谢你的帮助!

采纳答案by robrich

These files are staged but not committed. Yes, if you simply run git commit, they will be committed. More to the point, do you want to commit these files? They may or may not be the same as your working files. http://gitready.com/beginner/2009/01/18/the-staging-area.htmlis a decent introduction to the staging area.

这些文件已暂存但未提交。是的,如果您只是运行 git commit,它们将被提交。更重要的是,您要提交这些文件吗?它们可能与您的工作文件相同,也可能不同。 http://gitready.com/beginner/2009/01/18/the-staging-area.html是对暂存区的一个不错的介绍。

回答by Adam Dymitruk

Usually, if you want to take things as they are in the working folder you would

通常,如果您想按原样处理工作文件夹中的内容,您会

git add -A

which would stage all changes including the act of deleting a file and of tracking files that were not tracked yet.

这将暂存所有更改,包括删除文件和跟踪尚未跟踪的文件的行为。

It is wise to review your .gitignorefile before doing this so you don't commit unwanted artifacts which can bloat your repository and pollute the output of diffs and patches.

.gitignore在执行此操作之前检查您的文件是明智的,这样您就不会提交不需要的工件,这会使您的存储库膨胀并污染差异和补丁的输出。

Once you have done this you can

完成此操作后,您可以

git commit

to record the changes in history. Then you can

记录历史的变化。然后你可以

git push origin your_branch_name

to share this new history with the remote you set up.

与您设置的遥控器共享此新历史记录。