Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Troubleshooting misplaced .git directory (nothing to commit)

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?

like image 961
Andrius Avatar asked Feb 27 '14 12:02

Andrius


People also ask

Does .git folder get committed?

git folder contains all information that is necessary for the project and all information relating commits, remote repository address, etc. It also contains a log that stores the commit history.

How do I commit to a .git folder?

Enter git add --all at the command line prompt in your local project directory to add the files or changes to the repository. Enter git status to see the changes to be committed. Enter git commit -m '<commit_message>' at the command line to commit new files/changes to the local repository.

Why is git not adding a folder?

Git doesn't track folders, only files; you can't add an empty folder to a Git repo. However, you can put an empty file in that folder ( . gitignore or . blank are common file names) and add those files to the folder.

Where do I find a .git file?

git folder is store in ~/common/. git ( common is the name of the package).


2 Answers

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.

like image 162
Andrius Avatar answered Sep 23 '22 19:09

Andrius


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
like image 34
Mahi Avatar answered Sep 23 '22 19:09

Mahi