试图将文件添加到分支根目录的尝试失败,出现以下错误:
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 3839, in <module>
filter = RepoFilter(args)
File "C:/Program Files/Git/mingw64/libexec/git-core\git-filter-repo", line 2661, in __init__
self._handle_arg_callbacks()
File "C:/Program Files/Git/mingw64/libexec/git-core\git-filter-repo", line 2763, in _handle_arg_callbacks
handle('commit')
File "C:/Program Files/Git/mingw64/libexec/git-core\git-filter-repo", line 2756, in handle
setattr(self, callback_field, make_callback(type, code_string))
File "C:/Program Files/Git/mingw64/libexec/git-core\git-filter-repo", line 2741, in make_callback
exec('def callback({}, _do_not_use_this_var = None):\n'.format(argname)+
File "<string>", line 2
if not commit.parents: commit.file_changes.append(FileChange(b'M', 'C:\MDC\MDC.7z', 3d5fb68077a1d627a7ec3b18f335713c4262fbf0, 100644))
^
SyntaxError: invalid syntaxWindows 10
Git版本2.24
发布于 2019-11-25 14:22:36
从Python的角度来看,3d5fb68077a1d627a7ec3b18f335713c4262fbf0必须是一个字符串('3d5fb68077a1d627a7ec3b18f335713c4262fbf0'),所以在它周围加上引号:
--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))"发布于 2020-11-15 13:38:00
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'))"so:
100644 git rev-list --objects --all的路径。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.https://stackoverflow.com/questions/59032579
复制相似问题