Because I accidentally disconnected the hard drive from my laptop. I also faced some other problems in my other git repositories and after a while I could fix most of those issues. You can read about one of them (Git status fatal: bad object HEAD) here.
When I did:
in a git repository, I saw there was one untracked file which I had created already but had not been committed. Everything was okay until I started to add the file to the repository with:
git add .
git commit -m “message”
Suddenly I saw this error after git commit :
make_file.txt in the Collection directory (as shown in the above picture) is one of the old files that I’ve recently committed it! So there is a problem in the .git directory for this file: make_file.txt
As you see above in my case we see (file and its directory) in the terminal:
So grab it and put it in the next command without quotation mark. Like what I did: (Certainly you should put your specific file name and its directory)
git hash-object -w Collection/make-file.txt
After that, git will make a Sha1 for the make-file.txt and it’s repository will be fixed.
So the problem is solved! Then we could go forward and git add . and git commit like a normal condition. That’s it.
If you want to run all the git commands just in one command read this.
read more: here
Thank you for reading! If you enjoyed this article:
Clap it ! Share it! Follow Me in Medium!
Panjeh — Medium
Read writing from Panjeh on Medium. Physicists PhD, Self-taught web developer #Learning, #laravelphp #Vuejs. Every day…
Also I’d like to hear your opinion on this article. If you have any doubt, question or suggestion please leave a comment below.
Have a very wonderful day!
Previous Stories You will Love:
Makefile git add commit push github All in One command
As a remember, the traditional way of adding a file to a repository using the command line is summarized into 3 steps…
remove last commit local undo the most recent commit Git github repository
The solution is to first remove the last commit in local and then force push to Github