0

尝试将文件添加到分支的根目录失败并出现以下错误:添加了快速导入崩溃报告

git filter-repo --force --commit-callback "if not commit.parents: commit.file_changes.append(FileChange(b'M', 'C:\MDC\MDC.7z', '$(git hash-object -w 'C:\MDC\MDC.7z')', 100644))"
Traceback (most recent call last):
  File "C:/Program Files/Git/mingw64/libexec/git-core\git-filter-repo", line 3840, in <module>
    filter.run()
  File "C:/Program Files/Git/mingw64/libexec/git-core\git-filter-repo", line 3777, in run
    self._parser.run(self._input, self._output)
  File "C:/Program Files/Git/mingw64/libexec/git-core\git-filter-repo", line 1396, in run
    self._parse_commit()
  File "C:/Program Files/Git/mingw64/libexec/git-core\git-filter-repo", line 1249, in _parse_commit
    self._commit_callback(commit, aux_info)
  File "C:/Program Files/Git/mingw64/libexec/git-core\git-filter-repo", line 3334, in _tweak_commit
    self._insert_into_stream(commit)
  File "C:/Program Files/Git/mingw64/libexec/git-core\git-filter-repo", line 3752, in _insert_into_stream
    self._parser.insert(obj)
  File "C:/Program Files/Git/mingw64/libexec/git-core\git-filter-repo", line 1374, in insert
    obj.dump(self._output)
  File "C:/Program Files/Git/mingw64/libexec/git-core\git-filter-repo", line 702, in dump
    change.dump(file_)
  File "C:/Program Files/Git/mingw64/libexec/git-core\git-filter-repo", line 599, in dump
    quoted_filename = PathQuoting.enquote(self.filename)
  File "C:/Program Files/Git/mingw64/libexec/git-core\git-filter-repo", line 190, in enquote
    if unquoted_string.startswith(b'"') or b'\n' in unquoted_string:
TypeError: startswith first arg must be str or a tuple of str, not bytes
fatal: stream ends early
fast-import: dumping crash report to .git/fast_import_crash_14772

快速导入崩溃报告: https ://pastebin.com/DKrz883c

Windows 10
Git 版本 2.24

https://github.com/newren/git-filter-repo

4

2 回答 2

0

这似乎self.filename是 unicode 并且enquote适用于字节。

我对git-filter-repo. 可能'C:\MDC\MDC.7z'应该是字节:b'C:\MDC\MDC.7z'。或者也许这是一个错误;我建议在他们的问题跟踪器上报告这一点。

在 Python3 中,unicode 和字节字符串是不兼容的。看:

$ python3
Python 3.5.3 (default, Sep 27 2018, 17:25:39) 
[GCC 6.3.0 20170516] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> u'test'.startswith('"')
False

>>> u'test'.startswith(b'"')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: startswith first arg must be str or a tuple of str, not bytes

>>> b'test'.startswith('"')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: startswith first arg must be bytes or a tuple of bytes, not str

>>> b'test'.startswith(b'"')
False
于 2019-11-25T15:19:19.550 回答
0

Git filter-repo - 将文件添加到根提交失败


git filter-repo --force --commit-callback "if not commit.parents: commit.file_changes.append(FileChange(b'M', b'MDC.7z', bytes('$(git hash-object -w 'C:\MDC\MDC.7z')',encoding='utf-8'), b'100644'))"
  1. FileChange 的第二个参数应该像 rungit rev-list --objects --all的路径
  2. FileChange 的每个参数都必须是字节类型,所以:
  • 100644->b'100644'
  • $(git hash-object -w 'C:\MDC\MDC.7z')->bytes('$(git hash-object -w 'C:\MDC\MDC.7z')',encoding='utf-8')

例子:

$ git filter-repo --force --commit-callback "if not commit.parents: commit.file_changes.append(FileChange(b'M', b'1.txt', bytes('$(git hash-object -w 'D:\tmp\git\git1\1.txt')',encoding='utf-8'), b'100644'))"
Parsed 3 commitsHEAD is now at 067c5a4 add 5.txt
Enumerating objects: 10, done.
Counting objects: 100% (10/10), done.
Delta compression using up to 4 threads
Compressing objects: 100% (6/6), done.
Writing objects: 100% (10/10), done.
Total 10 (delta 2), reused 3 (delta 0)

New history written in 0.68 seconds; now repacking/cleaning...
Repacking your repo and cleaning out old unneeded objects
Completely finished after 2.18 seconds.
于 2020-11-15T13:45:27.810 回答