git “未为提交而暂存的更改”是什么意思

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

What does "Changes not staged for commit" mean

git

提问by newBike

I thought if you want to track the files you should git add [files you want to track]

我想如果你想跟踪你应该的文件 git add [files you want to track]

I don't know why I got the messages Changes not staged for commit.

我不知道为什么我收到了消息Changes not staged for commit

If those files were not staged, shouldn't gitshows me those files were Untrackedlike that

如果这些文件没有上演,就不应该git向我展示那些文件是 Untracked这样的

enter image description here

在此处输入图片说明

All I've done was create a new feature from developbranch and worked in feature/change_excel_formatbranch

我所做的只是从develop分支创建一个新功能并在feature/change_excel_format分支中工作

I thought Those files should be in stagedstatus,

我认为这些文件应该处于staged状态,

But git statustold me Changes not staged for commit

但是git status告诉我Changes not staged for commit

enter image description here

在此处输入图片说明

To brief, I only know there are 3 stages in git untracked, staged, committedCan any one tell me , what was the stage in for Changes not staged for commitenter image description here

为了简单,我只知道有3个阶段的git untrackedstagedcommitted任何一个可以告诉我,究竟是什么阶段了Changes not staged for commit在此处输入图片说明

So if I modified the file a(already in the repo)

所以如果我修改了文件a(已经在 repo 中)

and type git st, the git will tell me Changes not staged for commit

然后输入git st,git 会告诉我Changes not staged for commit

if I git athen the file awill be in staged status

如果我 git a那么文件a将在staged status

if I modified the file anow, there will be two status of file ain git, right ?

如果我修改了file anow ,会有两个状态file ain git,对吧?

So I have to decide if make the staged abe commit or make the not stage ato be staged, and then the previous staged file awill be discard ?

所以我必须决定是 make the staged abe commit 还是 make the not stage ato bestaged,然后之前的 stagedfile a将被丢弃?

enter image description here

在此处输入图片说明

回答by Stefano Falasca

when you change a file which is already in the repository, you have to git addit again if you want it to be staged.

当您更改存储库中已有的文件时,git add如果您希望将其暂存,则必须再次更改。

This allows you to commit only a subset of the changes you made since the last commit. For example, let's say you have file a, file band file c. You modify file aand file bbut the changes are very different in nature and you don't want all of them to be in one single commit. You issue

这允许您仅提交自上次提交以来所做更改的子集。例如,假设您有 file a、 fileb和 file c。您修改文件a和文件,b但更改的性质非常不同,您不希望所有更改都在一次提交中。你发出

git add a
git commit a -m "bugfix, in a"
git add b
git commit b -m "new feature, in b"

As a side note, if you want to commit everything you can just type

作为旁注,如果您想提交所有内容,您只需输入

git commit -a

Hope it helps.

希望能帮助到你。

回答by Dannie

You have to use git add to stage them, or they won't commit. Take it that it informs git which are the changes you want to commit.

您必须使用 git add 来暂存它们,否则它们将不会提交。假设它通知 git 哪些是您要提交的更改。

git add -u :/adds all modified file changes to the stage git add * :/adds modified and any new files (that's not gitignore'ed) to the stage

git add -u :/将所有修改后的文件更改git add * :/添加到舞台 将修改后的任何新文件(不是 gitignore 的)添加到舞台

回答by Agis

It's another way of Git telling you:

这是 Git 告诉你的另一种方式:

Hey, I see you made some changes, but keep in mind that when you write pages to my history, those changes won't be in these pages.

嘿,我看到您做了一些更改,但请记住,当您将页面写入我的历史记录时,这些更改不会出现在这些页面中。

Changes to files are not staged if you do not explicitly git addthem (and this makes sense).

如果您没有明确更改文件git add(这是有道理的),则不会暂存对文件的更改。

So when you git commit, those changes won't be added since they are not staged. If you want to commit them, you have to stage them first (ie. git add).

所以当你git commit,这些更改不会被添加,因为它们没有上演。如果您想提交它们,则必须先将它们暂存(即git add)。

回答by Mam's

Follow the steps below:

请按照以下步骤操作:

1- git stash
2- git add .
3- git commit -m "your commit message"

1- git stash
2- git add 。
3- git commit -m "你的提交信息"

回答by David Castro

Suposed you saved a new file changes. (navbar.component.html for example)

假设你保存了一个新的文件更改。(例如navbar.component.html)

Run:

跑:

ng status
modified:   src/app/components/shared/navbar/navbar.component.html

If you want to upload those changes for that file you must run:

如果要为该文件上传这些更改,则必须运行:

git add src/app/components/shared/navbar/navbar.component.html

And then:

进而:

git commit src/app/components/shared/navbar/navbar.component.html -m "new navbar changes and fixes"

And then:

进而:

git push origin [your branch name, usually "master"]

---------------------------------------------------------------

-------------------------------------------------- -------------

Or if you want to upload all your changes (several/all files):

或者,如果您想上传所有更改(几个/所有文件):

git commit -a

And them this will appear "Please enter the commit message for your changes."

他们会出现“请输入更改的提交消息”。

  • You'll see this message if you git commit without a message (-m)
  • You can get out of it with two steps:
  • 1.a. Type a multi-line message to move foward with the commit.
  • 1.b. Leave blank to abort the commit.
    1. Hit "esc" then type ":wq" and hit enter to save your choice. Viola!
  • 如果你 git commit 没有消息,你会看到这条消息 (-m)
  • 您可以通过两个步骤摆脱它:
  • 1.a. 键入多行消息以继续提交。
  • 1.b. 留空以中止提交。
    1. 点击“esc”,然后输入“:wq”并回车以保存您的选择。中提琴!

And then:

进而:

git push

And Viola!

还有维奥拉!

回答by Amila Weerasinghe

Try following int git bash

尝试遵循 int git bash

1.git add -u :/

1.git add -u :/

2.git commit -m "your commit message"

2.git commit -m "your commit message"

  1. git push -u origin master
  1. git push -u origin master

Note:if you have not initialized your repo.

注意:如果你还没有初始化你的仓库。

First of all

首先

git init 

and follow above mentioned steps in order. This worked for me

并按顺序执行上述步骤。这对我有用

回答by Waqas Khalid Obeidy

You may see this error when you have added a new file to your code and you're now trying to commit the code without staging(adding) it.

当您向代码添加新文件并且现在尝试提交代码而不暂存(添加)它时,您可能会看到此错误。

To overcome this, you may first add the file by using git add (git add your_file_name.py) and then committing the changes (git commit -m "Rename Files" -m "Sample script to rename files as you like")

为了克服这个问题,您可以先使用 git add ( git add your_file_name.py)添加文件,然后提交更改 ( git commit -m "Rename Files" -m "Sample script to rename files as you like")

回答by Ksaroz Shrestha

I have read all above replies and tried in terminal following steps which works fine for update new and changes files on master.

我已阅读上述所有回复并在终端中尝试执行以下步骤,这些步骤适用于更新 master 上的新文件和更改文件。

1) git add . 2) git commit -m "your message" 3) git push origin master

1) git 添加。2) git commit -m "你的消息" 3) git push origin master

I hope this helps you.

我希望这可以帮助你。

回答by LeMoN.xaH

it means they are not added to be committed you will have to do git add scripts/excel_parser.py and the likes to stage them .. once they are staged when you do git status they will be staged and git commit will commit them

这意味着它们不会被添加到提交你必须做 git add scripts/excel_parser.py 和类似的东西来暂存它们......一旦它们在你执行 git status 时被暂存,它们将被暂存并且 git commit 将提交它们

of you can git commit -a -m "all checkin" that will automatically stage and commit all the files in the tree

你可以 git commit -a -m "all checkin" 这将自动暂存并提交树中的所有文件

回答by aji stack

Remove dir/.../.git

消除 dir/.../.git

works for me.

对我来说有效。