SciTech-Github-解决git push时的 Error: hasDotgit: contains '.git'

发布时间 2024-01-10 12:20:50作者: abaelhe
AbaelsMacBookPro:pelican abaelhe$ git push
Enumerating objects: 6872, done.
Counting objects: 100% (6872/6872), done.
Delta compression using up to 8 threads
Compressing objects: 100% (4305/4305), done.
remote: error: object 93c3f3e6d30672571d972693d0842a14c4ffed26: hasDotgit: contains '.git'
remote: fatal: fsck error in packed object
error: remote unpack failed: index-pack failed
error: failed to push some refs to 
  'git@github.com:abaelhe/abaelhe.github.io.git'

Malformed objects in git repository #1692

I searched the issues for hasDotgit and found nobody reporting this issue yet.

I expected to be able to clone this git repository from Github but was unable to with the transfer.fsckobjects option set to true. When fetching objects from a remote this option will make git-fetch-pack check all fetched objects and abort when a malformed object or a broken link is encountered. See https://github.com/git/git/blob/d10e2cb9d0299a26f43d57dd5bdcf2b3f86a30b3/Documentation/config.txt#L2691-L2694 for information on transfer.fsckobjects option.

I tried to clone using the https, git and SSH methods of cloning from your organization's public repository URL. I also attempted to clone from a fork I created.

Here is an example of a failure. It fails on the same object SHA each time (031eba227fde3d82b8962537678701ac0cefbda6).

$ git clone git://github.com/zotonic/zotonic
Cloning into 'zotonic'...
remote: Counting objects: 86634, done.
error: object 031eba227fde3d82b8962537678701ac0cefbda6: hasDotgit: contains '.git'
fatal: Error in object
fatal: index-pack failed

I suggest you run the following to report all of the malformed objects or broken links in the repository since this option will only fail on the first problematic object in the git database.

$ git fsck --full                                      
Checking object directories: 100% (256/256), done.    
warning in tree 031eba227fde3d82b8962537678701ac0cefbda6: hasDotgit: contains '.git'
warning in tree 0c8472159b917c6e472a0f65b26be31a57021499: hasDotgit: contains '.git'
warning in tree 14a5cae41e98f08fd2f6d807283f07fc6141e8e9: hasDotgit: contains '.git'
Checking objects: 100% (86634/86634), done.

For reference here is the pertinent git config information for this problem:

$ git config transfer.fsckobjects
true
$ git --version
git version 2.12.2

The git config option fetch.fsckobjects set to true will also cause this error to surface.

When I searched for this tree SHA I found the following reference to it: http://chatlogs.jabber.ru/erlang-talks@conference.jabber.ru/2013/01/11.html

It lists the tree object looking like:

$ git ls-tree 031eba227fde3d82b8962537678701ac0cefbda6
040000 tree cd78065b172904253f823ac55e3210370af1cda1    .git
100644 blob a961122cf332c52bee5e678dd6243515a376c554    Emakefile
100644 blob 08b71726713a5840d2fbe9f671486f1468ddc8f9    License.txt
100644 blob f6aedc90f44016ba45ee6c4b012511cab194a638    Makefile
100644 blob d2ff5f9beb73303a38c88c6be7291bd56ff6a4ce    README.txt
040000 tree 6532097400540586342df1748ae64f3456b21652    ebin
040000 tree 0d4e2865bd5c984d6563701231b3b2b9bc58fcec    src

It appears as if the reason this tree object is malformed is because it contains a .git tree (aka directory) which is a little inception-like.

The date on the chat references is from 2012, so the commit is definitely not new.

I am not sure what can be done here but thought I would let you know that this will impact more and more people as checking git object integrity and links becomes more important from a security perspective.