对错放的 .git 目录进行故障排除(无需提交)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22067873/
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
Troubleshooting misplaced .git directory (nothing to commit)
提问by Andrius
I started getting this message. No matter what I edit and try to commit, it says there is nothing to commit. Looks like git does not see my working directory and looking somewhere else.
我开始收到这条消息。无论我编辑什么并尝试提交,它都说没有什么可提交的。看起来 git 没有看到我的工作目录并在其他地方寻找。
If I run git status
it outputs the same:
如果我运行git status
它输出相同的:
nothing to commit (working directory clean)
If I create new branch and edit something, then same thing happens. This started happening when I needed to fix merge clashes. When I wanted to merge my one branch with master branch, I had to manually fix it and I needed my files to look exactly as in that branch overwriting master branch those same files. So I added those files and it let me merge it. But then no matter what I change it shows as there is nothing to commit.
如果我创建新分支并编辑某些内容,则会发生同样的事情。当我需要修复合并冲突时,这开始发生。当我想将我的一个分支与 master 分支合并时,我必须手动修复它,并且我需要我的文件看起来与该分支中的文件完全一样,覆盖 master 分支那些相同的文件。所以我添加了这些文件,它让我合并它。但是无论我如何更改,它都显示为没有任何内容可提交。
What could be done here?
在这里可以做什么?
采纳答案by Andrius
Found what was wrong. I don't understand how, but .git
directory path somehow was changed to other path than I was working in. So then anything I changed was not checked, because git was checking in other place. I noticed it, when I reinitialized it and it showed that it reinitialized entirely different directory. When I cd ..
from my current directory and cd
to it back again and then reinitialized yet again, then it switched back to correct .git
directory and started seeing my changes.
发现哪里不对了。我不明白是怎么回事,但.git
目录路径不知何故被更改为我正在工作的其他路径。所以我更改的任何内容都没有检查,因为 git 正在其他地方检查。我注意到了,当我重新初始化它时,它显示它重新初始化了完全不同的目录。当我cd ..
从当前目录cd
返回并再次返回然后再次重新初始化时,它切换回正确的.git
目录并开始查看我的更改。
回答by Mahi
This must have happened because by mistake you reinitialized git in the same directory. Delete the .gitfolder using the following command Go to repository you want to upload open the terminal and then use the following commands
这一定发生了,因为您错误地在同一目录中重新初始化了 git。使用以下命令删除.git文件夹转到要上传的存储库打开终端,然后使用以下命令
- remove the .gitrepository
sudo rm -r .git
- Now again repeat from initializing git repo using
git init
- then
git commit -m "first commit"
git remote add origin https://github.com/user_name/repo
git push -u origin master
After that enter the username and password and you are good to go
- 删除.git存储库
sudo rm -r .git
- 现在再次重复使用初始化 git repo
git init
- 然后
git commit -m "first commit"
git remote add origin https://github.com/user_name/repo
git push -u origin master
之后输入用户名和密码,你就可以开始了
回答by palerdot
For people working in public open source projects, if you face this behaviour, it is most likely that the file you are editing is excluded from the git repository using .gitignore
. I faced the same behaviour, and after hours I found that the file I was making the change is excluded in .gitignore
because it is a settings file, and every one will have their own local version.
对于在公共开源项目中工作的人来说,如果您遇到这种行为,很可能是使用 .git 将您正在编辑的文件从 git 存储库中排除.gitignore
。我遇到了同样的行为,几小时后我发现我进行更改的文件被排除在外,.gitignore
因为它是一个设置文件,每个人都有自己的本地版本。
回答by Gank
Check the location whether it's the right location of the git project.
检查位置是否是 git 项目的正确位置。
回答by Anuj
On branch master Problem it is committed already nothing to commit (working directory clean)if faced this problem then just only use the following command
在分支主问题上,它已经没有提交任何内容(工作目录清理)如果遇到这个问题,那么只需使用以下命令
git push -u origin master
or
或者
git reset
git add .
git commit -m "your commit message"
git push -u origin master
回答by kaid
For anyone seeing this problem, the simplest solution I found was to just "git clone" your repo and delete the old directory. This should set up your pathing correctly by default.
对于任何看到这个问题的人,我找到的最简单的解决方案是“git clone”你的仓库并删除旧目录。默认情况下,这应该正确设置您的路径。
回答by Jon Kennedy
I had the same issue. The branch I was working on wasn't being tracked. The fix was:
我遇到过同样的问题。我正在处理的分支没有被跟踪。修复是:
git push orgin
This fixed it temporarily. To make the changes pertinently I:
这暂时修复了它。为了有针对性地进行更改,我:
git config push.default tracking
回答by Leviathan
In my case I had previously initialized a git directory where I was trying to create a new one. I just deleted all the old files and started from scratch.
就我而言,我之前已经初始化了一个 git 目录,我试图在其中创建一个新目录。我刚刚删除了所有旧文件并从头开始。
回答by rustylepord
Encountered this while using SourceTree, fixed it by
使用SourceTree 时遇到这个问题,通过
- First stash your current uncommitted changes.
- Apply / Unstash the same changes using Sourcetree.
- 首先存储您当前未提交的更改。
- 使用 Sourcetree 应用/取消隐藏相同的更改。
Worked like a charm.
像魅力一样工作。
回答by richardb
Here is another twist on it. My .gitignore file seemed to have been modified / corrupted so that a file I was ignoring
这是另一个转折点。我的 .gitignore 文件似乎已被修改/损坏,因此我忽略了一个文件
e.g.
例如
/Project/Folder/StyleCop.cache
got changed to this (Note now 2 separate lines)
改成这个(现在注意 2 个单独的行)
/Project/Folder
StyleCop.cache
so git was ignoring any files I added to the project and below.
所以 git 忽略了我添加到项目及以下的任何文件。
Very weird, no idea how the .gitignore file was changed, but took me a while to spot. Once fixed, the hundreds of css and js files I added went in.
非常奇怪,不知道 .gitignore 文件是如何更改的,但我花了一段时间才发现。一旦修复,我添加的数百个 css 和 js 文件就进去了。