简体   繁体   English

Git:使用 git add * -A 时不会暂存更改

[英]Git: Changes not staging when using git add * -A

Somehow, an .iml file has made its way into my git repo...不知何故,一个 .iml 文件进入了我的 git 仓库......

Here's how am I trying to get rid of it:这是我如何摆脱它:

  1. I cloned the latest version to a local folder我将最新版本克隆到本地文件夹
  2. Checked out the branch that I want to merge later into master检出我想稍后合并到 master 的分支
  3. Deleted myproject.iml (using windows gui)删除了 myproject.iml(使用 windows gui)
  4. edited .gitignore with extra line: *.iml用额外的行编辑 .gitignore: *.iml
  5. Trying to stage the changes: git add * -A尝试git add * -A更改: git add * -A
  6. Trying to commit: git commit -m"untrack .iml file and ignore for future commits"尝试提交: git commit -m"untrack .iml file and ignore for future commits"

Problem:问题:

On branch mybranch
Changes not staged for commit:
    modified:   .gitignore
    deleted:    myproject.iml

no changes added to commit

Why are they not staged for commit?为什么他们不准备提交? I thought -A would stage deletions too?我以为-A也会删除? And also, in any way, I thought changes (like the one I made to .gitignore) are added to staging area without any special parameters?而且,无论如何,我认为更改(例如我对 .gitignore 所做的更改)会添加到暂存区而没有任何特殊参数?

It's weird because just before that, I committed a huge 20-file all-nighter, with changes, deletions, additions, branch within branch, all the goodies, with no problems - using the exact same procedure!这很奇怪,因为就在此之前,我通宵提交了一个巨大的 20 文件,包括更改、删除、添加、分支内分支、所有好东西,没有任何问题 - 使用完全相同的程序!

Never use ' * ' with the git add command: ' * ' means shell expansion, which, in your case, would not include any .xxx file/folder.切勿在 git add 命令中使用 ' * ':' * ' 表示 shell 扩展,在您的情况下,它包括任何.xxx文件/文件夹。

Simply use:只需使用:

git add .

(Note the ' . ') (注意“ . ”)
No need for -A , which is the default anyway, since Git 2.0 .不需要-A ,这是默认值,因为 Git 2.0

For more on this, see " Difference between . (dot) and * (asterisk) wildcards in Git ".有关更多信息,请参阅“ Git 中. (点)和* (星号)通配符之间的区别”。

命令是“git add .”('.'而不是'*')并且不需要-A

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM