Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to generate a git patch with a local commit

Tags:

git

I'm contributing to the development of an open source project which use a git as a repository for the source code.

After do some modification on the source code I want to generate a patch containig my signature (email address and My name) and send it to the open source project maintainer.

How can I do it?

like image 222
MOHAMED Avatar asked Nov 02 '12 09:11

MOHAMED


People also ask

How do I apply a commit to a patch?

If you're using a JetBrains IDE (like IntelliJ IDEA, Android Studio, PyCharm), you can drag the patch file and drop it inside the IDE, and a dialog will appear, showing the patch's content. All you have to do now is to click "Apply patch", and a commit will be created.

How do I format a patch in git?

The first rule takes precedence in the case of a single <commit>. To apply the second rule, i.e., format everything since the beginning of history up until <commit>, use the --root option: git format-patch --root <commit> . If you want to format only <commit> itself, you can do this with git format-patch -1 <commit> .

Which command is used to create a patch for new commit?

If you want to create a patch for a specific commit, then use COMMIT_ID with the format-patch command.


1 Answers

1) Download source code from the git repository:

git clone git://address.of.repository/project/ /folder/path/on/my/computer

2) Do some modification on the source code. a new files/folders could be added in the project

3) set your email address and your name for the git commit signature:

git config --global user.name "Your Name"
git config --global user.email [email protected]

After doing this, you may fix the identity used for this commit with:

git commit --amend --reset-author

4) Before commit the changes. we have to add the new files/folders to the local git repository:

under the project folder of the source code

git add <Newfolder>
git add <Newfile>

4) And then commit locally the modification with:

under the project folder of the source code

commit -a

this will open an interactif window

you can check that commit has detected the edited files and the new files under:

# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#       modified:   bin/Makefile.am
#       modified:   configure.ac
#       new file:   src/new.c

under the window of commit -a, you have to enter comment for your modifications

and then save your commit with Ctrl + O ( WriteOut) and then Enter and your commit is become saved now

and then quit the commit -a window with Ctrl + X (Exit)

5) now you can generate your patch with:

under the project folder of the source code

git format-patch -1

this will generate a patch file with a name like 0001-...-...-.. .patch

If you want to generate patch with signed-off-by just add -s:

git format-patch -1 -s
like image 139
MOHAMED Avatar answered Sep 24 '22 19:09

MOHAMED