1+ /*
2+ * @Author: LetMeFly
3+ * @Date: 2024-12-31 15:31:56
4+ * @LastEditors: LetMeFly.xyz
5+ * @LastEditTime: 2025-01-01 17:58:11
6+ */
7+ 很棒 ,我已经完成了签名的验证 。现在我想要将一个commit重新签名 ,其他信息不变 。
8+ 可以做到吗 ?
9+
10+
11+
12+ git本地有两个用户 ,如何分别为其配置ssh公钥密钥
13+
14+
15+
16+ python写一个脚本 :
17+
18+ 从HEAD开始往前遍历 ,直到遇到可验证的签名为止 。
19+ 将HEAD开始的所有连续的不可验证的签名重新签名 。
20+
21+
22+
23+
24+ git log -- pretty = online可不可以指定显示数量
25+
26+
27+
28+
29+ git log -- pretty = online有没有办法从某次commit开始显示
30+
31+
32+
33+ 只输出commit hash
34+
35+
36+
37+ git某次commit的下一次commit
38+
39+
40+
41+ 不 ,比如我HEAD ~ 1 是HEAD的上一次commit
42+ 我如何表示一个commitHash的下一次commit
43+
44+
45+
46+ 为何我执行 `git filter-branch -f --commit-filter 'git commit-tree -S "$@";' HEAD~2..HEAD` 命令的时候
47+ 在终端中直接执行就能正常运行,而在python中调用os .system执行就会报错 :
48+
49+ `` `
50+ Proceeding with filter-branch...
51+
52+ fatal: ambiguous argument 'commit-tree': unknown revision or path not in the working tree.
53+ Use '--' to separate paths from revisions, like this:
54+ 'git <command> [<revision>...] -- [<file>...]'
55+ ` ``
56+
57+
58+
59+
60+ 执行如下代码时报错 :
61+
62+ `` `
63+ result = subprocess.run(
64+ ["git", "filter-branch", "-f", "--commit-filter", """'git commit-tree -S "$@";'""", f"{commit_hash}..HEAD"],
65+ check=True,
66+ text=True,
67+ # stdout=subprocess.PIPE,
68+ # stderr=subprocess.PIPE,
69+ )
70+ print(result.stdout)
71+ ` ``
72+
73+ `` `
74+ Rewrite bde2a1b75e8881d2911ec557aa0ae97414b75a47 (1/2) (0 seconds passed, remaining 0 predicted) git commit-tree: line 52: git commit-tree -S "$@";: command not found
75+ could not write rewritten commit
76+ Traceback (most recent call last):
77+ File "F:\OtherApps\Program\Git\Store\Store20_LeetCode\reassign.py", line 65, in <module>
78+ main()
79+ File "F:\OtherApps\Program\Git\Store\Store20_LeetCode\reassign.py", line 49, in main
80+ re_assign('HEAD~2')
81+ File "F:\OtherApps\Program\Git\Store\Store20_LeetCode\reassign.py", line 36, in re_assign
82+ result = subprocess.run(
83+ File "F:\OtherApps\Program\Python\Python\lib\subprocess.py", line 528, in run
84+ raise CalledProcessError(retcode, process.args,
85+ subprocess.CalledProcessError: Command '['git', 'filter-branch', '-f', '--commit-filter', '\'git commit-tree -S "$@";\'', 'HEAD~2..HEAD']' returned non-zero exit status 1.
86+ ` ``
87+
88+
89+
90+
91+
92+ 很棒 ,这个问题解决了 。
93+ 但是我发现了一个新的问题 ,在进行上述操作时 ,会显示如下warning并卡住几秒 。
94+ `` `
95+ Store\Store20_LeetCode\OtherSource\gitcode_knowledge
96+ WARNING: git-filter-branch has a glut of gotchas generating mangled history
97+ rewrites. Hit Ctrl-C before proceeding to abort, then use an
98+ alternative filtering tool such as 'git filter-repo'
99+ (https://github.com/newren/git-filter-repo/) instead. See the
100+ filter-branch manual page for more details; to squelch this warning,
101+ set FILTER_BRANCH_SQUELCH_WARNING=1.
102+ Proceeding with filter-branch...
103+ ` ``
104+ 我有没有办法让他不显示这个提示并且不卡住 ?
105+
106+
107+
108+
109+ `` `
110+ env = os.environ.copy()
111+ env['FILTER_BRANCH_SQUELCH_WARNING'] = 1
112+ result = subprocess.run(
113+ ["git", "filter-branch", "-f", "--commit-filter", 'git commit-tree -S "$@";', f"{commit_hash}..HEAD"],
114+ check=True,
115+ text=True,
116+ # stdout=subprocess.PIPE,
117+ # stderr=subprocess.PIPE,
118+ env=env,
119+ )
120+ ` ``
121+ 报错 :
122+ `` `
123+ File "F:\OtherApps\Program\Git\Store\Store20_LeetCode\reassign.py", line 68, in <module>
124+ main()
125+ File "F:\OtherApps\Program\Git\Store\Store20_LeetCode\reassign.py", line 52, in main
126+ re_assign('HEAD~2')
127+ File "F:\OtherApps\Program\Git\Store\Store20_LeetCode\reassign.py", line 38, in re_assign
128+ result = subprocess.run(
129+ File "F:\OtherApps\Program\Python\Python\lib\subprocess.py", line 505, in run
130+ with Popen(*popenargs, **kwargs) as process:
131+ File "F:\OtherApps\Program\Python\Python\lib\subprocess.py", line 951, in __init__
132+ self._execute_child(args, executable, preexec_fn, close_fds,
133+ File "F:\OtherApps\Program\Python\Python\lib\subprocess.py", line 1420, in _execute_child
134+ hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
135+ TypeError: environment can only contain strings
136+ ` ``
137+
138+
139+
140+ subprocess.CalledProcessError : Command '[' git ', 'filter - branch ', '-f ', '-- commit - filter ', 'git commit - tree - S "$@" ;', 'HEAD..HEAD ']' returned non - zero exit status 2.
141+ Found nothing to rewrite
0 commit comments