Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
424 views
in Technique[技术] by (71.8m points)

git - 为特定的提交生成一个git补丁(Generate a git patch for a specific commit)

I need to write a script that create patches for a list of SHA1 commit numbers.

(我需要编写一个脚本来为SHA1提交编号列表创建补丁。)

I tried using git format-patch <the SHA1> , but that generated a patch for each commit since that SHA1.

(我尝试使用git format-patch <the SHA1> ,但是自SHA1以来,每次提交都会生成一个补丁。)

After a few hundred patches were generated, I had to kill the process.

(生成几百个补丁后,我不得不终止该过程。)

Is there a way to generate a patch only for the specific SHA1?

(有没有一种方法只能为特定的SHA1生成补丁?)

  ask by elle translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Try:

(尝试:)

git format-patch -1 <sha>

or

(要么)

git format-patch -1 HEAD

According to the documentation link above, the -1 flag tells git how many commits should be included in the patch;

(根据上面的文档链接, -1标志告诉git补丁中应该包含多少个提交;)

-<n>

(-<n>)

Prepare patches from the topmost commits.

(从最顶层的提交准备补丁。)


Apply the patch with the command:

(使用以下命令应用补丁:)

git am < file.patch

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...