树包含重复的文件条目 [英] Tree contains duplicate file entries
问题描述
在我们托管的一些问题之后,我们决定将我们的Git仓库迁移到GitHub。所以我克隆了存储库,并尝试将其推送到GitHub。但是,我偶然发现我们从未遇到过的错误:
C:\repositories\appName [master]> git push -u origin master
计数对象:54483,完成。
使用最多2个线程的Delta压缩。
压缩对象:100%(18430/18430),完成。
错误:对象9eac1e639bbf890f4d1d52e04c32d72d5c29082e:包含重复的文件中的条目
致命:错误在对象
致命:SHA1文件 '<标准输出>' 写入错误:无效参数
错误:无法推送一些参考'ssh://git@github.com/User/Project.git'
当我运行 fsck
:
C:\repositories\appName [主] GT; git fsck --full
检查对象目录:100%(256/256),完成。在树0db4b3eb0e0b9e3ee41842229cdc058f01cd9c32
错误:包含树9eac1e639bbf890f4d1d52e04c32d72d5c29082e重复文件条目
错误:包含树4ff6e424d9dd2e3a004d62c56f99e798ac27e7bf重复文件条目
错误:包含重复的文件条目
检查对象:100%(54581 / 54581),完成。
当我运行 ls-tree
不好SHA1:
C:\repositories\appName [master]> GIT中LS-树9eac1e639bbf890f4d1d52e04c32d72d5c29082e
160000提交5de114491070a2ccc58ae8c8ac4bef61522e0667 MenuBundle
040000树9965718812098a5680e74d3abbfa26f527d4e1fb MenuBundle
我尝试了这个 StackOverflow问题中提供的所有答案,但是,没有任何成功。有什么办法可以防止这个存储库和历史记录被注定吗?
方法1。
首先执行 git fsck
$ GIT中的fsck --full在树bb81a5af7e9203f36c3201f2736fca77ab7c8f29
错误:包含重复的文件中的条目
如果这不能解决问题,你就会遇到麻烦。
您可以忽略该问题,从备份还原存储库,或将文件移动到新的存储库中。如果您无法将repo推送到github,请尝试将存储库更改为不同的存储库,或者检查:无法推送到GitHub错误:pack-objects死于信号13 和不能将新git存储库推送到github 。
以下方法仅适用于高级git用户。请在开始之前进行备份。该修复程序不能通过以下步骤来保证,它可以使它更糟糕,所以为了自己的风险或教育目的。
方法2。
使用git ls-tree来识别重复的文件。
$ git read-tree bb81a5af7e9203f36c3201f2736fca77ab7c8f29#只是一个提示。
$ git的LS-树bb81a5af7e9203f36c3201f2736fca77ab7c8f29#也尝试用:--full树-rt -l
160000犯def08273a99cc8d965a20a8946f02f8b247eaa66 commerce_coupon_per_user
100644一滴89a5293b512e28ffbaac1d66dfa1428d5ae65ce0 commerce_coupon_per_user
100644一滴2f527480ce0009dda7766647e36f5e71dc48213b commerce_coupon_per_user
100644团块dfdd2a0b740f8cd681a6e7aa0a65a0691d7e6059 commerce_coupon_per_user
100644团块45886c0eda2ef57f92f962670fad331e80658b16 commerce_coupon_per_user
100644团块9f81b5ca62ed86c1a2363a46e1e68da1c7b452ee commerce_coupon_per_user
如您所见,它包含重复的文件条目(commerce_coupon_per_user)!
$ git show bb81a5af7e9203f36c3201f2736fca77ab7c8f29
树bb81a5af7e9203f36c3201f2736fca77ab7c8f29
commerce_coupon_per_user
commerce_coupon_per_user
commerce_coupon_per_user
commerce_coupon_per_us er
commerce_coupon_per_user
commerce_coupon_per_user
再次,您可以看到重复的文件条目commerce_coupon_per_user)!
您可以尝试为每个列出的blob使用 git show
,并检查每个文件的内容。
然后在不同的git克隆之间继续运行无效的ls-tree对象的ls-tree,以查看是否可以跟踪有效的对象,或者是否全部被破坏。 / p>
git ls-tree bb81a5af7e9203f36c3201f2736fca77ab7c8f29
如果找到包含非重复文件条目的有效对象,请保存它进入文件并使用`git mktree`和`git replace`重新创建,例如
remote $ git ls-tree bb81a5af7e9203f36c3201f2736fca77ab7c8f29> work_tree.txt
$ cat working_tree.txt | git mktree
NEWTREEbb81a5af7e9203f36c3201f2736fca77ab7c8f29
$ git replace bb81a5af7e9203f36c3201f2736fca77ab7c8f29 NEWTREE4b825dc642cb6eb9a060e54bf8d69288fbee4904
如果不会帮助,您可以撤消的变化:
$ git的替代-d NEWTREE4b825dc642cb6eb9a060e54bf8d69288fbee4904
方法3。
当你知道哪个文件/目录条目被重复,您可能会尝试删除该文件并稍后重新创建。例如:
$ find。 -name commerce_coupon_per_user#查找重复条目。
$ git rm --cached`find。 -name commerce_coupon_per_user`#为目录添加-r。
$ git commit -m'现在删除无效的git条目'-a
$ git gc --aggressive --prune#删除松散的对象!请做好备份以防万一。
阅读更多:
方法4。
检查您提交的无效条目。
让我们再次查看我们的树。
$ git的LS-树bb81a5af7e9203f36c3201f2736fca77ab7c8f29 --full树-rt -l
160000提交def08273a99cc8d965a20a8946f02f8b247eaa66 commerce_coupon_per_user
100644团块89a5293b512e28ffbaac1d66dfa1428d5ae65ce0 270 commerce_coupon_per_user
....
$ git的节目def08273a99cc8d965a20a8946f02f8b247eaa66
致命的:坏对象def08273a99cc8d965a20a8946f02f8b247eaa66
$ git的猫文件提交def08273a99cc8d965a20a8946f02f8b247eaa66
致命的:git的猫文件def08273a99cc8d965a20a8946f02f8b247eaa66:坏文件
似乎以上提交是我无效,请使用以下命令之一扫描我们的git日志以查看发生的情况:
$ git log - C3 - 补丁|少+ / def08273a99cc8d965a20a8946f02f8b247eaa66
$ git log -C3 - 补丁| grep -C10 def08273a99cc8d965a20a8946f02f8b247eaa66
提交505446e02c68fe306aec5b0dc2ccb75b274c75a9
日期:7月3日16:06:25 2014 +0100
添加目录。
新文件模式160000
索引0000000..def0827
--- / dev / null
+++ b / sandbox / commerce_coupon_per_user
@@ -0,0 +1 @@
+子项目提交def08273a99cc8d965a20a8946f02f8b247eaa66
在这种特殊情况下,我们的提交指向不良对象,因为它被作为不再存在的git子项目的一部分(检查 git子模块状态
)。
您可以从ls树中排除该无效对象,并通过以下方式重新创建没有此对象的树:
$ git ls-tree bb81a5af7e9203f36c3201f2736fca77ab7c8f29 | grep -v def08273a99cc8d965a20a8946f02f8b247eaa66 |混帐mktree
b964946faf34468cb2ee8e2f24794ae1da1ebe20
$ git的替代bb81a5af7e9203f36c3201f2736fca77ab7c8f29 b964946faf34468cb2ee8e2f24794ae1da1ebe20
$ git的LS-树bb81a5af7e9203f36c3201f2736fca77ab7c8f29#重新测试。
$ git fsck -full
注意:旧对象还应该抛出重复的文件条目,但如果您现在在新树中重复,那么您需要从该树中删除更多的东西。所以:
$ git replace#列出替换对象。
bb81a5af7e9203f36c3201f2736fca77ab7c8f29
$ git replace -d bb81a5af7e9203f36c3201f2736fca77ab7c8f29#删除以前替换的对象。
现在,我们尝试从树中删除所有提交和blob,然后再次替换:
$ git ls-tree bb81a5af7e9203f36c3201f2736fca77ab7c8f29 | grep -ve commit -e blob | git mktree
4b825dc642cb6eb9a060e54bf8d69288fbee4904
$ git replace bb81a5af7e9203f36c3201f2736fca77ab7c8f29 4b825dc642cb6eb9a060e54bf8d69288fbee4904
现在你有空树为无效条目。
$ git status#检查一切是否正常。
$ git显示4b825dc642cb6eb9a060e54bf8d69288fbee4904#重新检查
$ git ls-tree 4b825dc642cb6eb9a060e54bf8d69288fbee4904 - 完整树#重新检查
如果您对舞台有一些奇怪的变化,请通过以下方式重置您的存储库:
$ git重置HEAD - hard
如果您将出现以下错误:
'pre>
HEAD现在处于5a4ed8e在bb81a5af7e9203f36c3201f2736fca77ab7c8f29
一些消息
执行rebase并删除该提交(通过将选择
更改为编辑
):
$ git rebase -i
$ git commit -m'Fixed invalid commit。'-a
rebase in progress;到691f725
您正在编辑一个提交,而在'691f725'上重新分支'dev'。
$ git rebase --continue
$ git重置--hard
$ git重置HEAD --hard
$ git重置原始/主--hard
方法5。
尝试删除和压缩包含无效对象的无效提交。
$ git rebase -i HEAD〜100#100在HEAD后面提交,如果需要增加
阅读更多: Git Tools - 重写历史和
方法6。
通过以下方法识别无效的git对象进行手动删除:
-
对于未压缩的对象(*请删除前两个字符,因为git用于目录名称):
$ find。 -name 81a5af7e9203f36c3201f2736fca77ab7c8f29
-
对于压缩对象
$ find。 -name \ * .idx -exec cat {} \; | git show-index | grep bb81a5af7e9203f36c3201f2736fca77ab7c8f29
#然后你需要手动查找文件。
$ git unpack-objects $ FILE#展开特定文件。
$ git unpack-objects< .git / objects / pack / pack - *。pack#全部展开。
请参阅:如何解压git存储库的所有对象?
相关:
- Git常见问题:如何修复破损的存储库?
- [SA] git tree包含重复的文件条目
- [SA] 如何在git仓库(新手)中恢复损坏的对象?
- [SA] 如何从tr中手动删除blob对象ee in Git?
- [SA] 如何恢复我的Git存储库中的缺失树错误?
- [SA] 如何在不使用git的情况下查看git对象和索引
- [SA] Git恢复:目标文件为空。如何重建树?
- [SA] 树包含重复的文件条目
- [SA] git树(仍然)包含重复和错误的信号13
- 撤消,修复或删除git中的提交
After some issues with our hosting, we decided to move our Git repository to GitHub. So I cloned the repository and tried pushing that to GitHub. However, I stumbled upon some errors we have never encountered before:
C:\repositories\appName [master]> git push -u origin master
Counting objects: 54483, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (18430/18430), done.
error: object 9eac1e639bbf890f4d1d52e04c32d72d5c29082e:contains duplicate file entries
fatal: Error in object
fatal: sha1 file '<stdout>' write error: Invalid arguments
error: failed to push some refs to 'ssh://git@github.com/User/Project.git'
When I run fsck
:
C:\repositories\appName [master]> git fsck --full
Checking object directories: 100% (256/256), done.
error in tree 0db4b3eb0e0b9e3ee41842229cdc058f01cd9c32: contains duplicate file entries
error in tree 9eac1e639bbf890f4d1d52e04c32d72d5c29082e: contains duplicate file entries
error in tree 4ff6e424d9dd2e3a004d62c56f99e798ac27e7bf: contains duplicate file entries
Checking objects: 100% (54581/54581), done.
When I run ls-tree
with the bad SHA1:
C:\repositories\appName [master]> git ls-tree 9eac1e639bbf890f4d1d52e04c32d72d5c29082e
160000 commit 5de114491070a2ccc58ae8c8ac4bef61522e0667 MenuBundle
040000 tree 9965718812098a5680e74d3abbfa26f527d4e1fb MenuBundle
I tried all of the answers already given on this StackOverflow question, but haven't had any success. Is there any way I can prevent this repository and its history from being doomed?
Method 1.
Do the git fsck
first.
$ git fsck --full
error in tree bb81a5af7e9203f36c3201f2736fca77ab7c8f29: contains duplicate file entries
If this won't fix the problem, you're in trouble. You can either ignore the problem, restore the repository from the backup, or move the files into new repository. If you having trouble pushing the repo into github, try changing the repository to different one or check: Can't push to GitHub error: pack-objects died of signal 13 and Can't push new git repository to github.
The below methods are only for advanced git users. Please do the backup before starting. The fix is not guaranteed by the following steps and it can make it even worse, so do it for your own risk or education purposes.
Method 2.
Use git ls-tree to identify duplicate files.
$ git read-tree bb81a5af7e9203f36c3201f2736fca77ab7c8f29 # Just a hint.
$ git ls-tree bb81a5af7e9203f36c3201f2736fca77ab7c8f29 # Try also with: --full-tree -rt -l
160000 commit def08273a99cc8d965a20a8946f02f8b247eaa66 commerce_coupon_per_user
100644 blob 89a5293b512e28ffbaac1d66dfa1428d5ae65ce0 commerce_coupon_per_user
100644 blob 2f527480ce0009dda7766647e36f5e71dc48213b commerce_coupon_per_user
100644 blob dfdd2a0b740f8cd681a6e7aa0a65a0691d7e6059 commerce_coupon_per_user
100644 blob 45886c0eda2ef57f92f962670fad331e80658b16 commerce_coupon_per_user
100644 blob 9f81b5ca62ed86c1a2363a46e1e68da1c7b452ee commerce_coupon_per_user
As you can see, it contains the duplicated file entries (commerce_coupon_per_user)!
$ git show bb81a5af7e9203f36c3201f2736fca77ab7c8f29
tree bb81a5af7e9203f36c3201f2736fca77ab7c8f29
commerce_coupon_per_user
commerce_coupon_per_user
commerce_coupon_per_user
commerce_coupon_per_user
commerce_coupon_per_user
commerce_coupon_per_user
Again, you can see the duplicated file entries (commerce_coupon_per_user)!
You may try to use git show
for each listed blob and check the content if each file.
Then keep running ls-tree for that invalid ls-tree object across your different git clones to see if you can track the valid object, or if all are broken.
git ls-tree bb81a5af7e9203f36c3201f2736fca77ab7c8f29
If you found the valid object containing non-duplicated file entries, save it into the file and re-create by using `git mktree` and `git replace`, e.g.
remote$ git ls-tree bb81a5af7e9203f36c3201f2736fca77ab7c8f29 > working_tree.txt
$ cat working_tree.txt | git mktree
NEWTREEbb81a5af7e9203f36c3201f2736fca77ab7c8f29
$ git replace bb81a5af7e9203f36c3201f2736fca77ab7c8f29 NEWTREE4b825dc642cb6eb9a060e54bf8d69288fbee4904
If this won't help, you can undo the change by:
$ git replace -d NEWTREE4b825dc642cb6eb9a060e54bf8d69288fbee4904
Method 3.
When you know which file/dir entry is duplicated, you may try to remove that file and re-create it later on. In example:
$ find . -name commerce_coupon_per_user # Find the duplicate entry.
$ git rm --cached `find . -name commerce_coupon_per_user` # Add -r for the dir.
$ git commit -m'Removing invalid git entry for now.' -a
$ git gc --aggressive --prune # Deletes loose objects! Please do the backup before just in case.
Read more:
Method 4.
Check your commit for invalid entries.
Lets check our tree again.
$ git ls-tree bb81a5af7e9203f36c3201f2736fca77ab7c8f29 --full-tree -rt -l
160000 commit def08273a99cc8d965a20a8946f02f8b247eaa66 commerce_coupon_per_user
100644 blob 89a5293b512e28ffbaac1d66dfa1428d5ae65ce0 270 commerce_coupon_per_user
....
$ git show def08273a99cc8d965a20a8946f02f8b247eaa66
fatal: bad object def08273a99cc8d965a20a8946f02f8b247eaa66
$ git cat-file commit def08273a99cc8d965a20a8946f02f8b247eaa66
fatal: git cat-file def08273a99cc8d965a20a8946f02f8b247eaa66: bad file
It seems the above commit is invalid, lets scan our git log for this commit using one of the following commands to check what's going on:
$ git log -C3 --patch | less +/def08273a99cc8d965a20a8946f02f8b247eaa66
$ git log -C3 --patch | grep -C10 def08273a99cc8d965a20a8946f02f8b247eaa66
commit 505446e02c68fe306aec5b0dc2ccb75b274c75a9
Date: Thu Jul 3 16:06:25 2014 +0100
Added dir.
new file mode 160000
index 0000000..def0827
--- /dev/null
+++ b/sandbox/commerce_coupon_per_user
@@ -0,0 +1 @@
+Subproject commit def08273a99cc8d965a20a8946f02f8b247eaa66
In this particular case, our commit points to the bad object, because it was commited as part of git subproject which doesn't exist anymore (check git submodule status
).
You may exclude that invalid object from the ls-tree and re-create tree without this bad object by e.g.:
$ git ls-tree bb81a5af7e9203f36c3201f2736fca77ab7c8f29 | grep -v def08273a99cc8d965a20a8946f02f8b247eaa66 | git mktree
b964946faf34468cb2ee8e2f24794ae1da1ebe20
$ git replace bb81a5af7e9203f36c3201f2736fca77ab7c8f29 b964946faf34468cb2ee8e2f24794ae1da1ebe20
$ git ls-tree bb81a5af7e9203f36c3201f2736fca77ab7c8f29 # Re-test.
$ git fsck -full
Note: The old object should still throw the duplicate file entries, but if you've now duplicates in the new tree, then you need to remove more stuff from that tree. So:
$ git replace # List replace objects.
bb81a5af7e9203f36c3201f2736fca77ab7c8f29
$ git replace -d bb81a5af7e9203f36c3201f2736fca77ab7c8f29 # Remove previously replaced object.
Now lets try to remove all commits and blobs from that tree, and replace is again:
$ git ls-tree bb81a5af7e9203f36c3201f2736fca77ab7c8f29 | grep -ve commit -e blob | git mktree
4b825dc642cb6eb9a060e54bf8d69288fbee4904
$ git replace bb81a5af7e9203f36c3201f2736fca77ab7c8f29 4b825dc642cb6eb9a060e54bf8d69288fbee4904
Now you have empty tree for that invalid entry.
$ git status # Check if everything is fine.
$ git show 4b825dc642cb6eb9a060e54bf8d69288fbee4904 # Re-check
$ git ls-tree 4b825dc642cb6eb9a060e54bf8d69288fbee4904 --full-tree # Re-check
If you have some weird changes for stage, reset your repository by:
$ git reset HEAD --hard
If you'll have the following error:
HEAD is now at 5a4ed8e Some message at bb81a5af7e9203f36c3201f2736fca77ab7c8f29
Do the rebase and remove that commit (by changing pick
to edit
):
$ git rebase -i
$ git commit -m'Fixed invalid commit.' -a
rebase in progress; onto 691f725
You are currently editing a commit while rebasing branch 'dev' on '691f725'.
$ git rebase --continue
$ git reset --hard
$ git reset HEAD --hard
$ git reset origin/master --hard
Method 5.
Try removing and squashing invalid commits containing invalid objects.
$ git rebase -i HEAD~100 # 100 commits behind HEAD, increase if required.
Read more: Git Tools - Rewriting History and How do I rebase while skipping a particular commit?
Method 6.
Identifying the invalid git objects by the following methods for manual removal:
for uncompressed objects (*please remove first two characters, as git uses it for the directory name):
$ find . -name 81a5af7e9203f36c3201f2736fca77ab7c8f29
for compressed objects
$ find . -name \*.idx -exec cat {} \; | git show-index | grep bb81a5af7e9203f36c3201f2736fca77ab7c8f29 # Then you need to find the file manually. $ git unpack-objects $FILE # Expand the particular file. $ git unpack-objects < .git/objects/pack/pack-*.pack # Expand all.
See: How to unpack all objects of a git repository?
Related:
- Git FAQ: How to fix a broken repository?
- [SA] git tree contains duplicate file entries
- [SA] How do you restore a corrupted object in a git repository (for newbies)?
- [SA] How can I manually remove a blob object from a tree in Git?
- [SA] How can I recover my Git repository for a "missing tree" error?
- [SA] How to view git objects and index without using git
- [SA] Git recovery: "object file is empty". How to recreate trees?
- [SA] Tree contains duplicate file entries
- [SA] git tree (still) contains duplicates and an erroneous signal 13
- On undoing, fixing, or removing commits in git
这篇关于树包含重复的文件条目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!