Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git format-patch for all the commits to a file

I want to get patches for all commits that are made to a file/folder.

I can get the list of commit-id through git log --format="%H"-- path/to/folder

Is there a way i can get generate patches from this list.

[edit]:

below code partly solves my problem

for c in `git log --format="%H" -- path/to/file`;do git format-patch "$c^1".."$c" -o patches ; done

since format-patch is called individually, i will get patches all numbered 0001-commit-text.patch where i will lose the order of patches. Is there any better solutions

like image 792
prahlad venkata Avatar asked Jan 23 '18 11:01

prahlad venkata


2 Answers

Come up with the below shell script to achieve this. any other answers are welcome.

#!/bin/bash
COUNTER=1;
for c in `git log --format="%H" --reverse -- path/to/file`;do
    git format-patch --start-number=$COUNTER "$c^1".."$c" -o patches
    let COUNTER=COUNTER+1
done
like image 83
prahlad venkata Avatar answered Sep 22 '22 11:09

prahlad venkata


You can try git diff initial_commit_id..latest_commit_id > changes.patch

This is based on this article: https://www.lullabot.com/articles/git-best-practices-upgrading-the-patch-process

For example:

git diff ab0b3a55de5..6f5dbbc4187b97

Update: if you provide the path to the specific file as an argument to format-patch it'll only create patches for the commits with changes to that file. So no need for the loop and one-by-one invocation of format-patch. See example in format-patch for a single file

So try this:

get format-patch from..to -o patches /path/to/file 
like image 36
kofman Avatar answered Sep 24 '22 11:09

kofman