Troubleshooting misplaced .git directory (nothing

2019-01-14 00:14发布

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.

If I run git status it outputs the same:

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.

What could be done here?

17条回答
对你真心纯属浪费
2楼-- · 2019-01-14 00:38

Here is another twist on it. My .gitignore file seemed to have been modified / corrupted so that a file I was ignoring

e.g.

/Project/Folder/StyleCop.cache

got changed to this (Note now 2 separate lines)

/Project/Folder
StyleCop.cache

so git was ignoring any files I added to the project and below.

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.

查看更多
\"骚年 ilove
3楼-- · 2019-01-14 00:40

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.

查看更多
Luminary・发光体
4楼-- · 2019-01-14 00:41

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
查看更多
太酷不给撩
5楼-- · 2019-01-14 00:41

I have faced the same issue with git while working with angular CLI 6.1.2. Angular CLI 6.1.2 automatically initializes .git folder when you create a new angular project using Angular CLI. So when I tried git status - it was not detecting the whole working directory.

I have just deleted the hidden .git folder from my angular working directory and then initialized git repository again with git init. And now, I can see all my files with git status.

查看更多
啃猪蹄的小仙女
6楼-- · 2019-01-14 00:42

Check the location whether it's the right location of the git project.

查看更多
放我归山
7楼-- · 2019-01-14 00:43

try removing the origin first before adding it again

git remote rm origin
git remote add origin https://github.com/abc/xyz.git
查看更多
登录 后发表回答