I broke my (local) git repository. The problem comes from my python script that added files with names starting with './'.
When I try to git push, I get this:
Counting objects: 6, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (5/5), done.
Writing objects: 100% (6/6), 4.03 KiB | 0 bytes/s, done.
Total 6 (delta 1), reused 0 (delta 0)
remote: error: object a6cc7dfb40e8c513415315d6ed84143448bd4f99: hasDot: contains '.'
remote: fatal: Error in object
error: unpack failed: unpack-objects abnormal exit
To [email protected]:xxx/yyy.git
! [remote rejected] master -> master (unpacker error)
error: failed to push some refs to '[email protected]:xxx/yyy.git'
When Googling the only thing close to my problem is this unanswered SO question where the author has the hasDotgit: contains '.git' error
I ran git show a6cc7dfb40e8c513415315d6ed84143448bd4f99:
./
./file1
./file2
...
file1
file2
...
And git fsck --full:
warning in tree a6cc7dfb40e8c513415315d6ed84143448bd4f99: hasDot: contains '.'
I think I have to delete the ./files in git but git rm "./file1" removes the regular file1 file, not ./file1. And if I run the command again I get this:
fatal: pathspec './file1' did not match any files
I don't know what to do because I find absolutely nothing on internet about this problem and even a search in the git source code doesn't show any result. And I'd rather fix this in plain git than using the python module again (which by the way also gives me the fatal: pathspec error when I try to delete the files).
Edit1: git ls-tree --long --abbrev --full-name a6cc7dfb40e8c513415315d6ed84143448bd4f99
040000 tree 22b75ee - .
100644 blob d519532 3580 file1
...
100644 blob 03e914c 6754 fileN
No ./file in the list
Edit2: Same result if --full-tree instead of --full-name
Looks like it's not possible without reverting the bad commit.
If someone else looks for hasDot or hasDotgit, you can fix with that:
git reset --soft fbc2d1cae724acc7b8d83442ca94088d836fea55
#delete all commits after the last good one (fbc2), but keep files (--soft)
git rm --cached "." -r -f #git rm all files but keep them locally (--cached)
git add . #git add everything back
git commit -m "msg"
I know that my answer is late but it may help others.
I used git-filter-repo to rewrite my entire project history by excluding any path that was mentioning .git
(in our case those were obsolete files that shouldn't be committed in the first place).
git filter-repo --invert-paths --path-glob '*.git'
git-filter-repo
installation instructions can be found here or here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With