如何使用 git 提交文件?

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

How can I commit files with git?

git

提问by Kirk Strobeck

None of the tutorials will help!
They all do that thing where they just assume I know what to do..

没有任何教程会有所帮助!
他们都做那件事,他们只是假设我知道该怎么做..

Currently, my terminal window starts with..

目前,我的终端窗口以..

# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#       deleted:    httpdocs/newsite/manifest/cache/0a432970ba6491fe65dad60b012e5c95_louloumay2011en-1-4dea3186b7f7b.jpg
#       deleted:    httpdocs/newsite/manifest/cache/0a61b5d7a9e97da78fe602e1ad41edb6_5-4dec7c3d57c80.jpg
#       deleted:    httpdocs/newsite/manifest/cache/0afb6a7716a85d0de46cdd03bb30f75f_fifa_panorama_full_page-01_thu-4dea3d1a0e0f5.jpg
#       deleted:    httpdocs/newsite/manifest/cache/0b3bc9be76a5d3e1e36af4b8dcf98658_free2-4df0e2e08761f.jpg
#       deleted:    httpdocs/newsite/manifest/cache/0b6342913b8e599fac76da452af98ec5_si-feb-2009-1-4dea3d1abcb61.jpg
#       deleted:    httpdocs/newsite/manifest/cache/0b9ddc587340f7744e03c4b2dafacf7f_lou-lou-winter-2009-cover-4dea3d1a9b1a0.jpg
#       deleted:    httpdocs/newsite/manifest/cache/0bf64ff8fc22720b3da20d0730fa6a04_chatelaine-dec-2009-4dea3d18daa30.jpg
#       deleted:    httpdocs/newsite/manifest/cache/0bf664e03eb0a2255b69b02aed85add0_summumfeb2011-2-4dea3188766aa.jpg

but there's no way to know how to do what they say to do here..
http://learn.github.com/p/normal.html

但没有办法知道如何按照他们说的去做..
http://learn.github.com/p/normal.html

All it says is

它所说的只是

We simply type our commit message and exit the editor.

我们只需输入我们的提交消息并退出编辑器。

What does that mean?!
Just because you write the word simplydoesn't mean it is simple..

这意味着什么?!
仅仅因为你写的字根本不意味着它很简单..

When I start to type it does wierd stuff, says "recording" or "inserting" and there are about 300 files, and it wants me to replace every line with a message?!?

当我开始打字时,它会做一些奇怪的事情,说“录音”或“插入”,大约有 300 个文件,它要我用一条消息替换每一行?!?

Help !

帮助 !

I would use their handy Mac application for this, but if it's over 20 files or so, it freezes up !
What's up with that??

为此,我会使用他们方便的 Mac 应用程序,但如果文件超过 20 个左右,它就会冻结!
那是怎么回事??

回答by Ben James

When you run git commitwith no arguments, it will open your default editor to allow you to type a commit message. Saving the file and quitting the editor will make the commit.

当您git commit不带参数运行时,它将打开您的默认编辑器以允许您输入提交消息。保存文件并退出编辑器将进行提交。

It looks like your default editor is Vi or Vim. The reason "weird stuff" happens when you type is that Vi doesn't start in insert mode - you have to hit ion your keyboard first! If you don't want that, you can change it to something simpler, for example:

看起来您的默认编辑器是 Vi 或 Vim。键入时出现“奇怪的东西”的原因是 Vi 没有以插入模式启动 - 您必须先敲击i键盘!如果您不希望那样,可以将其更改为更简单的内容,例如:

git config --global core.editor nano

Then you'll load the Nano editor (assuming it's installed!) when you commit, which is much more intuitive for users who've not used a modal editor such as Vi.

然后,您将在提交时加载 Nano 编辑器(假设它已安装!),这对于未使用 Vi 等模态编辑器的用户来说更加直观。

That text you see on your screen is just to remind you what you're about to commit. The lines are preceded by #which means they're comments, i.e. Git ignores those lines when you save your commit message. You don't need to type a message per file - just enter some text at the top of the editor's buffer.

您在屏幕上看到的文本只是为了提醒您将要提交的内容。这些行在前面,#这意味着它们是注释,即当您保存提交消息时,Git 会忽略这些行。您不需要为每个文件键入消息 - 只需在编辑器缓冲区的顶部输入一些文本即可。

To bypass the editor, you can provide a commit message as an argument, e.g.

要绕过编辑器,您可以提供提交消息作为参数,例如

git commit -m "Added foo to the bar"

回答by Mark Longair

It sounds as if the only problem here is that the default editor that is launched is vior vim, with which you're not familiar. (As quick tip, to exit that editor without saving changes, hit Esca few times and then type :, q, !and Enter.)

听起来好像这里唯一的问题是启动的默认编辑器是vivim,您不熟悉它。(由于快速提示,退出该编辑器而不保存更改,打Esc了几下,然后键入:q!Enter)。

There are several ways to set up your default editor, and you haven't indicated which operating system you're using, so it's difficult to recommend one in particular. I'd suggest using:

设置默认编辑器的方法有多种,但您尚未指明使用的是哪种操作系统,因此很难特别推荐一种。我建议使用:

 git config --global core.editor "name-of-your-editor"

... which sets a global git preference for a particular editor. Alternatively you can set the $EDITORenvironment variable.

... 为特定编辑器设置全局 git 首选项。或者,您可以设置$EDITOR环境变量。

回答by Oner Ksor

in standart Vi editor in this situation you should

在这种情况下,在标准 Vi 编辑器中,您应该

  1. press Esc
  2. type ":wq" (without quotes)
  3. Press Enter
  1. 按 Esc
  2. 输入“:wq”(不带引号)
  3. 按 Enter

回答by pkk

I don't know your system environment, but it seems, that you have typed:

我不知道您的系统环境,但您输入的似乎是:

git commit

And your default editor has been launched. In the worst case scenario (for you) it could have been vim :)

您的默认编辑器已启动。在最坏的情况下(对你来说)它可能是 vim :)

If you don't know how to quit vim, use :q.

如果您不知道如何退出 vim,请使用 :q。

If you have further problems, you could use

如果您有进一步的问题,您可以使用

git commit -m 'Type your commit message here'

回答by Ali

The command for commiting all changed files:

提交所有更改文件的命令:

git commit -a -m 'My commit comments'

-a= all edited files

-a= 所有编辑过的文件

-m= following string is a comment.

-m= 后面的字符串是注释。

This will commit to your local drives / folders repo. If you want to push your changes to a git server / remotely hosted server, after the above command type:

这将提交到您的本地驱动器/文件夹存储库。如果要将更改推送到 git 服务器/远程托管服务器,请在上述命令后键入:

git push

GitHub's cheat sheetis quite handy.

GitHub 的备忘单非常方便。

回答by knittl

Git uses "the index" to prepare commits. You can add and remove changes from the index before you commit (in your paste you already have deleted ~10 files with git rm). When the index looks like you want it, run git commit.

Git 使用“索引”来准备提交。您可以在提交之前从索引中添加和删除更改(在您的粘贴中,您已经删除了大约 10 个文件git rm)。当索引看起来像您想要的那样时,运行git commit.

Usually this will fire up vim. To insert text hit i, <esc>goes back to normal mode, hit ZZto save and quit (ZQto quit without saving). voilà, there's your commit

通常这会启动vim。要插入文本 hit i<esc>返回正常模式,点击ZZ保存并退出(ZQ不保存退出)。瞧,这是你的承诺

回答by juliarm

This happens when you do not include a message when you try to commit using:

当您尝试使用以下方法提交时未包含消息时,会发生这种情况:

git commit

It launches an editor environment. Quit it by typing :q!and hitting enter.

它启动一个编辑器环境。通过键入:q!并按回车键退出。

It's going to take you back to the terminal without committing, so make sure to try again, this time pass in a message:

它会带你回到终端而不提交,所以一定要再试一次,这次传递一条消息:

git commit -m 'Initial commit'

回答by kelvin nyadzayo

I faced the same problem , i resolved it by typing :q!then hit EnterAnd it resolved my problem After that run the the following command git commit -a -m "your comment here"

我遇到了同样的问题,我通过输入:q!然后点击Enter解决了它解决了我的问题之后运行以下命令 git commit -a -m "your comment here"

This should resolve your problem.

这应该可以解决您的问题。

回答by JaredPar

It looks like all of the edits are already a part of the index. So to commit just use the commitcommand

看起来所有的编辑都已经是索引的一部分。所以要提交只需使用commit命令

git commit -m "My Commit Message"

Looking at your messages though my instinct says that you probably don't want the cachefiles to be included in your depot. Especially if it something that is built on the fly when running your program. If so then you should add the following line to your .gitignore file

尽管我的直觉告诉您,您可能不希望这些cache文件包含在您的仓库中,但查看您的消息。特别是如果它是在运行程序时即时构建的。如果是这样,那么您应该将以下行添加到您的 .gitignore 文件中

httpdocs/newsite/manifest/cache/*