git github 更改未暂存以进行提交

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

github changes not staged for commit

gitgithub

提问by Ryan Tice

I have a very basic github setup with a readme, a directory, and another directory inside it with an html file. On github I can only view the readme and the first folder but none of its contents, and I am getting this message

我有一个非常基本的 github 设置,其中包含一个自述文件、一个目录和另一个包含 html 文件的目录。在 github 上,我只能查看自述文件和第一个文件夹,但不能查看其中的任何内容,并且收到此消息

tc349 ryntc3$ git add *
tc349 ryntc3$ git status
On branch master
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
(commit or discard the untracked or modified content in submodules) 

modified:   week1 (modified content)

no changes added to commit (use "git add" and/or "git commit -a")

I feel like if I am adding all to be staged that it should not be an issue. Any help?

我觉得如果我将所有内容都添加到舞台上,那应该不是问题。有什么帮助吗?

采纳答案by ivo Welch

Is week1a submodule?

week1子模块吗?

Note the relevant part from the output of the git statuscommand:

请注意git status命令输出中的相关部分:

(commit or discard the untracked or modified content in submodules)

(提交或丢弃子模块中未跟踪或修改的内容)

Try cd week1and issuing another git statusto see what changes you have made to the week1submodule.

尝试cd week1发出另一个git status以查看您week1对子模块所做的更改。

See http://git-scm.com/book/en/Git-Tools-Submodulesfor more information about how submodules work in Git.

有关子模块如何在 Git 中工作的更多信息,请参阅http://git-scm.com/book/en/Git-Tools-Submodules

回答by g-eorge

Have you tried

你有没有尝试过

git add .

This recurses into sub-directories, whereas I don't think * does.

这会递归到子目录中,而我认为 * 不会。

See here

这里

回答by Waleed Asender

WARNING!THIS WILL DELETE THE ENTIRE GIT HISTORY FOR YOUR SUBMODULE. ONLY DO THIS IF YOU CREATED THE SUBMODULE BY ACCIDENT. CERTAINLY NOT WHAT YOU WANT TO DO IN MOST CASES.

警告!这将删除您的子模块的整个 Git 历史记录。仅当您意外创建子模块时才执行此操作。在大多数情况下,这当然不是您想要做的。

I think you have to go inside week1folder and delete the .gitfolder:

我认为您必须进入week1文件夹并删除.git文件夹:

sudo rm -Rf .git

then go back to top level folder and do:

然后返回顶级文件夹并执行以下操作:

git add .

then do a commit and push the code.

然后提交并推送代码。

回答by ivo Welch

in my case, I needed a

就我而言,我需要一个

 git add files
 git commit -am 'what I changed'
 git push

the 'a' on the commit was needed.

需要提交上的“a”。

回答by Marvin W

WARNING!THIS WILL DELETE THE ENTIRE GIT HISTORY FOR YOUR SUBMODULE. ONLY DO THIS IF YOU CREATED THE SUBMODULE BY ACCIDENT. CERTAINLY NOT WHAT YOU WANT TO DO IN MOST CASES.

警告!这将删除您的子模块的整个 Git 历史记录。仅当您意外创建子模块时才执行此操作。在大多数情况下,这当然不是您想要做的。

In my situation, there was a sub-directory which had a .gitdirectory.

在我的情况下,有一个包含.git目录的子目录。

What I do is simply remove that .gitdirectory from my sub-directory.

我所做的只是.git从我的子目录中删除该目录。

回答by Chris

I was having the same problem. I ended up going into the subdirectory that was "not staged for commit" and adding, committing and pushing from there. after that, went up one level to master directory and was able to push correctly.

我遇到了同样的问题。我最终进入了“未为提交而暂存”的子目录,并从那里添加、提交和推送。之后,上一级到主目录并能够正确推送。

回答by apebeast

For me, I had to commit the subdirectories which had .gitin it since both the parent and the subfolder have remotes to push to. And then commit and push the parent directory.

对我来说,我必须提交其中包含的子目录,.git因为父文件夹和子文件夹都有要推送到的遥控器。然后提交并推送父目录。

回答by Belachkar Ali

This command may solve the problem :

这个命令可以解决问题:

git add -A

git add -A

All the files and subdirectories will be added to be tracked.

所有文件和子目录都将被添加以进行跟踪。

Hope it helps

希望能帮助到你

回答by Austin Reid

If it's a submodule you need to cd into it then use git add . && git commit -m 'Your message'

如果它是一个子模块,你需要 cd 进入它然后使用 git add . && git commit -m 'Your message'

From there you can cd out and push to whichever branch you want.

从那里你可以退出并推送到你想要的任何分支。

回答by Unnit Metaliya

I tried everything suggested on whole Stackoverflow. Nothing including -a or -am or anything helped.

我尝试了整个 Stackoverflow 上建议的所有内容。没有包括 -a 或 -am 或任何帮助。

If you are the same, do this.

如果你是一样的,请这样做。

So, the problem is, git thinks some of your subdirectory is sub-project in your root-project. At least, in my case it wasn't like that. It was just regular sub-directory. Not individual project.

所以,问题是,git 认为您的某些子目录是根项目中的子项目。至少,就我而言,情况并非如此。它只是普通的子目录。不是个人项目。

Move that regular sub-directory which is not being pushed at some temporary location.

移动没有被推送到某个临时位置的常规子目录。

Remove the hidden .git folder from that directory.

从该目录中删除隐藏的 .git 文件夹。

cdto the root directory.

cd到根目录。

git initagain.

git init再次。

git add .again.

git add .再次。

git commit -m "removed notPushableDirectory temporarily"

git commit -m "removed notPushableDirectory temporarily"

git push -f origin master

git push -f origin master

We will have to force it as the git will see the conflict between remote git and your local structure. Remember, we created this conflict. So, don't worry about forcing it.

我们将不得不强制它,因为 git 会看到远程 git 和您的本地结构之间的冲突。请记住,我们制造了这场冲突。所以,不要担心强迫它。

Now, it will push that sub-directory as sub-directory and not as sub-module or sub-project inside your root-project.

现在,它将将该子目录作为子目录而不是作为根项目中的子模块或子项目推送。