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:28

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.

查看更多
叼着烟拽天下
3楼-- · 2019-01-14 00:29

Go to your workspace folder

  1. find .git folder
  2. delete the folder and its contents
  3. use git init command to initialize.

Now it will show what all the files can be committed.

查看更多
我想做一个坏孩纸
4楼-- · 2019-01-14 00:31

This must have happened because by mistake you reinitialized git in the same directory. Delete the .git folder using the following command Go to repository you want to upload open the terminal and then use the following commands

  1. remove the .git repository sudo rm -r .git
  2. Now again repeat from initializing git repo using git init
  3. then git commit -m "first commit"
  4. git remote add origin https://github.com/user_name/repo
  5. git push -u origin master After that enter the username and password and you are good to go
查看更多
放荡不羁爱自由
5楼-- · 2019-01-14 00:31

I just had this problem myself because I was in the wrong folder. I was nested 1 level in, so there were no git files to be found.

When I execute cd .. to the correct directory, I was able to commit, as expected.

查看更多
我只想做你的唯一
6楼-- · 2019-01-14 00:33

Encountered this while using SourceTree, fixed it by

  1. First stash your current uncommitted changes.
  2. Apply / Unstash the same changes using Sourcetree.

Worked like a charm.

查看更多
走好不送
7楼-- · 2019-01-14 00:36

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.

查看更多
登录 后发表回答