Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create a patch by comparing a specific branch on the remote with a specific local branch

Tags:

git

I've been working with git for a few weeks, but now I'd like to contribute back to this open source project. I've merged my work with the latest, remote by pulling editing out conflicts and it all looks the way it should in gitk. Now I need to create a patch that is against the latest version of origin (remote) master. So I thought the following command would work:

git format-patch origin:master --stdout > 25032011.patch

but I get:

fatal: Invalid object name 'origin'.

So I've obviously got the command wrong. So how would I create a patch by comparing a specific branch on the remote with a specific local branch?

like image 911
justify Avatar asked Mar 25 '11 12:03

justify


People also ask

How do I compare a local branch to a remote?

You can git branch -a to list all branches (local and remote) and then choose the branch name from the list (just remove remotes/ from the remote branch name. Example: git diff main origin/main (where "main" is the local main branch and "origin/main" is a remote, namely the origin and main branch.)

How do I pull a remote branch and create a local branch?

Use git branch -a (both local and remote branches) or git branch -r (only remote branches) to see all the remotes and their branches. You can then do a git checkout -t remotes/repo/branch to the remote and create a local branch. There is also a git-ls-remote command to see all the refs and tags for that remote.


2 Answers

Use git format-patch origin/master. This creates a patch file for each commit on your checked out branch, which is not in origin/master.

To have one file instead of multiple files you can use

git format-patch master --stdout > mypatch.patch 
like image 125
Rudi Avatar answered Sep 25 '22 19:09

Rudi


Use this to create one file containing all commits in your current branch that are not in the master branch:

git format-patch master --stdout > mypatch.patch 
like image 38
batigolix Avatar answered Sep 23 '22 19:09

batigolix