Donnerstag, 31. März 2016

Creating a patch by Git

Firstly create a new Git branch: 

git checkout -b my-new-branch

Do your changes and commit:

git commit -am "My changes."
Now create the patch file by a diff from your branch and the development branch (f.e. master or develop):

git format-patch master --stdout > fix_empty_poster.patch 
Afterwards you can switch into a different branch, where you want to apply the patch file.

git checkout master

To check if the patch can be applied, use the following command:

git apply --check fix_empty_poster.patch 
To check which impact the patch will have, use the following command:

git apply --stat fix_empty_poster.patch
You can also apply the patch by

git apply < fix_empty_poster.patch

But this command will not create a Git commit by one action.

For applying the patch, use the following command:

git am --signoff < fix_empty_poster.patch 
 By this command, the patch will be already commited into Git. So you'll the the following entry in your Git log, if you type

git log

commit 2839f6f8e408140956d121b2af28b55543e93ec0
Author: Peter
Date:   Wed Mar 30 21:04:21 2016 +0200
    Patch commit.
 
    Signed-off-by: Peter
This article is based on Ariejan de Vroom's article.

The commands in short

New branch:
git checkout -b my-new-branch

Do changes and commit:
git commit -am "My changes."

Create the patch:
git format-patch master --stdout > fix_empty_poster.patch

Checkout to your master branch (or any other):
git checkout master

Check if patch can be applied:
git apply --check fix_empty_poster.patch 

Check the impact:
git apply --stat fix_empty_poster.patch

Apply and commit the patch:
git am --signoff < fix_empty_poster.patch 

Keine Kommentare:

Kommentar veröffentlichen