Difference between revisions of "GitPhraseBook"

From Openembedded.org
Jump to: navigation, search
(Start with the mtn phrasebook from http://web.archive.org/web/20080205023301/http://www.openembedded.org/wiki/MonotonePhraseBook)
 
m (Example 3: Working with a private branch)
 
(78 intermediate revisions by 23 users not shown)
Line 1: Line 1:
MonotonePhraseBook
+
= Git Phrase Book =
  
    * View
 
    * diff
 
  
Sun, 2006-05-28 14:50 — Openembedded Team
+
'''NOTE:''' For increased pleasure use git 1.5 or later.
  
NOTE: You need to have monotone 0.32 now !
+
== Pointers ==
 +
There are plenty of good git tutorials on the net. A small collection of links can be seen below:
  
Add the following command to your .bashrc:
+
* [http://git.or.cz/gitwiki/GitDocumentation Official Documentation]
 +
* [http://git.or.cz/gitwiki/GitCheatSheet Cheat Sheet]
 +
* [http://book.git-scm.com/ The Git Community Book]
 +
* [http://eagain.net/articles/git-for-computer-scientists/ Git For Computer Scientists]
 +
* [http://progit.org/book/ Pro Git]
 +
* [http://www.google.com/search?q=git+documentation&ie=utf-8&oe=utf-8&aq=t Google Search]
  
alias mtn-add='mtn list unknown | xargs mtn add'
+
== Setup ==
alias mtn-drop='mtn drop --missing'
 
  
mtn-add will put new files under monotone control and mtn-drop will remove files from monotone control.
 
  
To start with you need to init a database:
+
=== Getting the data (read-only) ===
 +
  git clone git://git.openembedded.org/openembedded
  
mtn db init --db=/somepath/OE.mtn
+
=== Getting the data (write-access) ===
  
Developers with write access need to generate a key and send it to mickeyl and koen:
+
For this command to succeed you need to have provided a SSH key (see [[#Generating a ssh key]]).
  
#yes, that really needs to be <name>@openembedded.org
+
  git clone git@git.openembedded.org:openembedded
mtn genkey --db=/somepath/OE.mtn xxx@openembedded.org
 
mtn --db=/somepath/OE.mtn pubkey xxx@openembedded.org | mail mickeyl@linuxtogo.org -s "xxx monotone key"
 
mtn --db=/somepath/OE.mtn pubkey xxx@openembedded.org | mail koen@linuxtogo.org -s "xxx monotone key"
 
  
You can then pull openembedded and check out the repository to edit (see details on branches dev,oz354x,dreambox in DevelopmentBranches) :
+
=== Generating a ssh key ===
 +
To be able to push to the OpenEmbedded git server you will need to have the right permissions. This starts with having your public ssh key on the server. Generate a key and send the public key to the one of the core developers.
  
mtn --db=/somepath/OE.mtn pull monotone.openembedded.org "org.openembedded.{dev,oz354x,dreambox}"
+
  # send the resulting pub key to koen, mickeyl, RP, or zecke [http://lists.linuxtogo.org/pipermail/openembedded-devel/2008-October/006291.html [email address]]
mtn --db=/somepath/OE.mtn co --branch=org.openembedded.dev
+
  ssh-keygen -t rsa or -t dsa
  
 +
=== Upgrading your data (lurking) ===
 +
  git pull --rebase
  
Committing
+
This command will fetch new objects from the server, and try to put your local changes on top of the newly fetched revisions for your current branch. If you have no local revisions you will still be updated.
  
mtn pull
+
Depending on your git version this command may fail and does not report any error message: Version 1.5.6.5 (Debian Lenny) does, 1.5.5.1 (Fedora 9) does not. The message is
mtn update
+
"refusing to pull with rebase: your working tree is not up-to-date".
mtn commit <files>
 
  
 +
In case that 'git pull --rebase' does not work for you, try the following:
  
When you are committing someone elses work verbatim:
+
  git stash
 +
  git pull --rebase
 +
  git stash pop
  
mtn pull
+
This information was taken from the [http://wiki.videolan.org/Git#Setting_up_.22git_up.22_.28Tip.29 VideoLAN Wiki].
mtn update
 
mtn commit <files> --author <email of original author>
 
  
 +
=== Checking out a branch ===
 +
  # See which branches are available
 +
  git branch -a
  
The commit message has to follow this layout:
+
  # In theory create a branch and switch
 +
  git checkout -b local origin/remote
  
<package name> <version>| <package category> | <configfile/class name>: <summary>
+
  # you will now be in the dreambox branch and track this.
- <detail 1>
+
  git checkout -b org.openembedded.dreambox origin/org.openembedded.dreambox
  - <detail 2>}*
 
  
Example 1:
+
=== Configuring your tree for commits ===
  
vi packages/gaim/gaim.inc
+
If you forget this, your name and email in the commit mails, may be messed up.
mtn pull
+
 
mtn update
+
  git config user.name "Your Name"
mtn commit packages/gaim/gaim.inc
+
  git config user.email "you@name"
 +
 
 +
== Doing things with git ==
 +
 
 +
=== Commit Message ===
 +
<package name> <version>| <package category> | <configfile/class name>: <summary>
 +
{  - <detail 1>
 +
    - <detail 2>}*
 +
 
 +
=== Making your changes (old way) ===
 +
  # if you have new files
 +
  git add your/new/file
 +
 
 +
  # Commit everything
 +
  git commit -a
 +
 
 +
=== Making your changes (better way) ===
 +
  git add your/changed/files
 +
  git commit
 +
 
 +
=== Making your changes (a cool way) ===
 +
  git add -i
 +
  git commit
 +
 
 +
=== Automatically add 'Signed-off-by:' statement ===
 +
  git commit -s
 +
 
 +
=== Amending to your changes ===
 +
You forgot something, no big deal, change the commit
 +
 
 +
  git add your/others/changes
 +
  git commit --amend
 +
 
 +
== Commiting someones else work ==
 +
  git commit --author "Other One <other@one>"
 +
 
 +
== Create patches suitable for the mailing list  ==
 +
This creates a series of patches of all your added work
 +
  git format-patch origin
 +
You can add a 'Signed-off-by:' statement by
 +
  git format-patch -s origin
 +
 
 +
== Create series of patches suitable for the mailing list  ==
 +
Include the last 17 commits.
 +
 
 +
The patches will have a header [PATCH n/17]
 +
  git format-patch -n -17
 +
 
 +
== Create version 2 of a patch after feedback from the mailing list ==
 +
  git format-patch -n -17 --subject-prefix='PATCH v2'
 +
 
 +
== Send email to mailing list ==
 +
  git send-email <patch-list>
 +
 
 +
== Pushing your changes ==
 +
  # just pushes the org.openembedded.dev
 +
  git push origin org.openembedded.dev
 +
 
 +
  # the same, just simpler
 +
  git push
 +
 
 +
  # just pushes your things to a test branch. Use the right branch! dangerous!
 +
  git push origin yourname/testbranch
 +
 
 +
  # delete a branch
 +
  git push origin :yourname/testbranch
 +
 
 +
== Dealing with conflicts ==
 +
Git will tell you what needs resolving. You can use kdiff3, meld, or many other tools to resolve the conflict. Don't be afraid you can easily redo and undo everything.
 +
 
 +
  # Conflicts from here or something else
 +
  git pull --rebase
 +
  git status
 +
 
 +
  # Starts interactive resolver, TOOL can be kdiff3, meld or anything else
 +
  git mergetool --tool=TOOL filename
 +
 
 +
  git rebase --continue or similar once everything got resolved
 +
 
 +
== Working with git ==
 +
=== Feature branches ===
 +
==== Create your own short lived feature branch ====
 +
  git checkout -b yourname/yourfeature origin/org.openembedded.dev
 +
 
 +
==== Push your feature branch ====
 +
  git push origin yourname/yourfeature
 +
 
 +
==== Delete your branch after it was merged ====
 +
  git push origin :yourname/yourfeature
 +
 
 +
==== Prune remote branches which have been deleted ====
 +
  git remote prune origin
 +
 
 +
==== Upgrade/Rebase your branch to the latest version ====
 +
  git fetch origin
 +
  git rebase origin/org.openembedded.dev
 +
 
 +
==== Change your history ====
 +
  # select edit, squash, pick to say what to do with the commit
 +
 
 +
  git rebase -i origin/org.openembedded.dev
 +
 
 +
  # to abort the operation on a tricky merge
 +
  git rebase --abort
 +
 
 +
  # to find out a previous state to use with git reset
 +
  git reflog
 +
 
 +
== Seeing changes ==
 +
 
 +
=== Log ===
 +
  # See what happened in a branch
 +
  git log branch
 +
 
 +
  # See the change, HEAD or branch name will work too
 +
  git show --color (COMMIT)
 +
 
 +
  # Only show you change on foo/file
 +
  git show --color HEAD -- foo/file
 +
 
 +
  # Graphical browser
 +
  gitk
 +
 
 +
=== What did you change ===
 +
  # Lists you the revs that are only in your branch compared to org.openembedded.dev
 +
  git rev-list origin/org.openembedded.dev..
 +
 
 +
== Other Interesting commands ==
 +
  # fetch new revisions from all remote repositories
 +
  git fetch
 +
 
 +
  # show your local branches and which branch you are in
 +
  git branch
 +
 
 +
  # show all branches
 +
  git branch -a
 +
 
 +
  # create a branch and switch to it
 +
  git checkout -b MYNAME origin/THEIRNAME
 +
 
 +
  # upgrade a branch
 +
  git push origin org.openembedded.dev
 +
  git reflog
 +
 
 +
  # Change your index to be at the state of REF
 +
  git reset REF
 +
 
 +
  # Kill the last commit
 +
  git reset HEAD^1
 +
 
 +
  # Prepare a set of patch
 +
  git format-patch origin
 +
 
 +
  # What changes have I made
 +
  git status
 +
 
 +
  # List details of those changes
 +
  git diff --cached
 +
 
 +
== Working with additional git repositories ==
 +
One of the neat things with git is you can easily work with external repositories.  
 +
  # add an external repository:
 +
  git remote add openmoko.org git://git.openmoko.org/git/openmoko.git
 +
  git fetch openmoko.org
 +
 
 +
  # view all remote branches available
 +
  git branch -r
 +
 
 +
  # view changes on a remote branch
 +
  gitk openmoko.org/org.openmoko.asu.stable
 +
  git log openmoko.org/org.openmoko.asu.stable
 +
 
 +
  # view all diffs
 +
  git diff origin/org.openembedded.dev openmoko.org/org.openmoko.asu.stable
 +
 
 +
  # view diffs in just one subdirectory
 +
  git diff origin/org.openembedded.dev openmoko.org/org.openmoko.asu.stable classes
 +
 
 +
 
 +
== Examples ==
 +
 
 +
 
 +
=== Example 1: ===
 +
 
 +
  vi packages/gaim/gaim.inc
 +
  git commit packages/gaim/gaim.inc
 +
  git pull --rebase
  
 
should have a log message like this:
 
should have a log message like this:
  
gaim: make sure do_install does its job in gaim.inc
+
gaim: make sure do_install does its job in gaim.inc
* install lib to ${libdir} instead of /usr/lib
+
* install lib to ${libdir} instead of /usr/lib
* remove executable bits from docs
+
* remove executable bits from docs
  
Example 2:
+
=== Example 2: ===
  
diff /tmp/foo.c /oe/work/gtk+-2.8.4-r0/gtk+-2.8.4/src/foo.c > gtk-2.8.4/fix-foo.patch
+
diff /tmp/foo.c /oe/work/gtk+-2.8.4-r0/gtk+-2.8.4/src/foo.c > gtk-2.8.4/fix-foo.patch
vi gtk+_2.8.4.bb
+
vi gtk+_2.8.4.bb
mtn add gtk-2.8.4/fix-foo.patch
+
  git add gtk-2.8.4/fix-foo.patch
mtn  pull
+
  git commit gtk-2.8.4/fix-foo.patch gtk+_2.8.4.bb
mtn  update
+
git pull --rebase
mtn commit gtk-2.8.4/fix-foo.patch gtk+_2.8.4.bb
 
  
 
should have a log message like this:
 
should have a log message like this:
  
gtk+ 2.8.4: add patch for buffer overflow
+
gtk+ 2.8.4: add patch for buffer overflow
 +
 
 +
=== Example 3: Working with a private branch ===
 +
 
 +
Download and create a remote private branch "origin/ulf/linux-2.6.39-2011-11-22".
 +
The local copy of the branch will be called "ulf/linux-2.6.39-2011-11-22".
 +
When you do:
 +
 
 +
git branch -a
 +
 
 +
local branches will be at the top, and remote branches
 +
will be sorted in alpabetical order.
  
Note: Make sure you do 'mtn update' before 'mtn commit' since this reduces the possibility of multiple heads.
+
Create the local branch and prepare:
  
Backing out the commit you've made: (You'll need to find the revision ID for this. Use mtn log|less)
+
git clone git@git.openembedded.org:openembedded
 +
cd openembedded
 +
git config user.name "Ulf Samuelsson"
 +
git config user.email "ulf_samuelsson@telia.com"
 +
git checkout -b ulf/linux-2.6.39-2011-11-22 origin/org.openembedded.dev
  
This will remove all changes you've done, returning the file(s) to the state they were before you edited them.
+
Add something:
  
mtn --db=OE.mtn --branch=org.openembedded.<branchname> disapprove 5c1a5813e0f66a0d10515ba6fecafbebfe679c7f
+
  touch test
 +
git add test
 +
git commit -m "test" test
  
Updating
+
Create a remote private branch from the local branch.
 +
It will be called "origin/ulf/linux-2.6.39-2011-11-22"
  
It is assumed that the database is in the current directory and named OE.mtn and the checkout tree is in the org.openembedded.dev in the same directory. Specifying the server name is optional after the initial pull.
+
git push origin ulf/linux-2.6.39-2011-11-22
  
mtn  --db=OE.mtn pull monotone.openembedded.org org.openembedded.dev
+
Create a local branch, based on your remote private branch:
cd org.openembedded.dev
 
  
The database now contains all upstream changes. You can review the incoming changes as follows:
+
git checkout -b ulf/linux-2.6.39-2011-11-22 origin/ulf/linux-2.6.39-2011-11-22
  
mtn diff -r `mtn automate get_base_revision_id` -r `mtn automate heads`
+
Add something to your local branch:
  
Update your local checkout:
+
touch test2
 +
git add test2
 +
git commit -m "test2" test2
  
mtn  update
+
Update your remote private branch:
  
Pushing your changes upstream:
+
git push origin ulf/linux-2.6.39-2011-11-22
  
cd org.openembedded.dev
+
Once the remote branch has been updated from a local
mtn  pull
+
branch you need to update any other local branches by:
mtn  merge
 
mtn  push
 
  
Set default branch and server on push (this is especially needed if you download the database snapshot and want pushing to monotone.openembedded.org):
+
git fetch origin
  
mtn  push --set-default <server> org.openembedded.dev
+
Prepare patches for the mailing list:
  
http://www.venge.net/monotone/docs/Tutorial.html contains lots of useful examples.
+
git format-patch origin
Working on multiple branches
 
  
If you have checked-out different branches, the default settings (set on first checkout) stored in your database may not fit for other branches. You may need to reset vars in order to be able to pull updates in other branches' local copies. For instance, to continue work on org.openembedded.oz354x instead of org.openembedded.dev  :
+
Remove your local branch:
  
mtn set database default-include-pattern org.openembedded.oz354x
+
  git checkout origin/org.openembedded.dev
 +
git branch -d ulf/llinux-2.6.39-2011-11-22
  
You can check default settings with :
+
or possibly:
  
mtn list vars
+
  git branch -D ulf/linux-2.6.39-2011-11-22
  
Some additional guidelines:
+
Note that the openembedded git server will not
 +
allow you to delete a private branch at this time.
 +
Send an email to the mailing list and this will be fixed.
  
    * If you have multiple trees / databases, make sure you synchronize them with the upstream tree before pushing or we'll end up with multiple branch heads
+
[[Category:Dev]]
    * Don't forget to update your working copies after pulling
+
[[Category:User]]
    * If you are responsible for multiple branch heads, feel responsible to merge them using 'mtn merge'
 
    * Install 'meld' of 'kdiff3' on your PC, this eases 2-way and 3-way merging
 

Latest revision as of 20:42, 22 November 2011

Git Phrase Book

NOTE: For increased pleasure use git 1.5 or later.

Pointers

There are plenty of good git tutorials on the net. A small collection of links can be seen below:

Setup

Getting the data (read-only)

 git clone git://git.openembedded.org/openembedded

Getting the data (write-access)

For this command to succeed you need to have provided a SSH key (see #Generating a ssh key).

 git clone git@git.openembedded.org:openembedded

Generating a ssh key

To be able to push to the OpenEmbedded git server you will need to have the right permissions. This starts with having your public ssh key on the server. Generate a key and send the public key to the one of the core developers.

 # send the resulting pub key to koen, mickeyl, RP, or zecke [email address]
 ssh-keygen -t rsa or -t dsa

Upgrading your data (lurking)

 git pull --rebase

This command will fetch new objects from the server, and try to put your local changes on top of the newly fetched revisions for your current branch. If you have no local revisions you will still be updated.

Depending on your git version this command may fail and does not report any error message: Version 1.5.6.5 (Debian Lenny) does, 1.5.5.1 (Fedora 9) does not. The message is "refusing to pull with rebase: your working tree is not up-to-date".

In case that 'git pull --rebase' does not work for you, try the following:

 git stash
 git pull --rebase
 git stash pop

This information was taken from the VideoLAN Wiki.

Checking out a branch

 # See which branches are available
 git branch -a
 # In theory create a branch and switch
 git checkout -b local origin/remote
 # you will now be in the dreambox branch and track this.
 git checkout -b org.openembedded.dreambox origin/org.openembedded.dreambox

Configuring your tree for commits

If you forget this, your name and email in the commit mails, may be messed up.

 git config user.name "Your Name"
 git config user.email "you@name"

Doing things with git

Commit Message

<package name> <version>| <package category> | <configfile/class name>: <summary> 
{  - <detail 1>
   - <detail 2>}*

Making your changes (old way)

 # if you have new files
 git add your/new/file
 # Commit everything
 git commit -a

Making your changes (better way)

 git add your/changed/files
 git commit

Making your changes (a cool way)

 git add -i
 git commit

Automatically add 'Signed-off-by:' statement

 git commit -s

Amending to your changes

You forgot something, no big deal, change the commit

 git add your/others/changes
 git commit --amend

Commiting someones else work

 git commit --author "Other One <other@one>"

Create patches suitable for the mailing list

This creates a series of patches of all your added work

 git format-patch origin

You can add a 'Signed-off-by:' statement by

 git format-patch -s origin

Create series of patches suitable for the mailing list

Include the last 17 commits.

The patches will have a header [PATCH n/17]

 git format-patch -n -17

Create version 2 of a patch after feedback from the mailing list

 git format-patch -n -17 --subject-prefix='PATCH v2'

Send email to mailing list

 git send-email <patch-list>

Pushing your changes

 # just pushes the org.openembedded.dev
 git push origin org.openembedded.dev
 # the same, just simpler
 git push
 # just pushes your things to a test branch. Use the right branch! dangerous!
 git push origin yourname/testbranch
 # delete a branch
 git push origin :yourname/testbranch

Dealing with conflicts

Git will tell you what needs resolving. You can use kdiff3, meld, or many other tools to resolve the conflict. Don't be afraid you can easily redo and undo everything.

 # Conflicts from here or something else
 git pull --rebase
 git status
 # Starts interactive resolver, TOOL can be kdiff3, meld or anything else
 git mergetool --tool=TOOL filename
 git rebase --continue or similar once everything got resolved

Working with git

Feature branches

Create your own short lived feature branch

 git checkout -b yourname/yourfeature origin/org.openembedded.dev

Push your feature branch

 git push origin yourname/yourfeature

Delete your branch after it was merged

 git push origin :yourname/yourfeature

Prune remote branches which have been deleted

 git remote prune origin

Upgrade/Rebase your branch to the latest version

 git fetch origin
 git rebase origin/org.openembedded.dev

Change your history

 # select edit, squash, pick to say what to do with the commit
 git rebase -i origin/org.openembedded.dev
 # to abort the operation on a tricky merge
 git rebase --abort
 # to find out a previous state to use with git reset
 git reflog

Seeing changes

Log

 # See what happened in a branch
 git log branch
 # See the change, HEAD or branch name will work too
 git show --color (COMMIT)
 #  Only show you change on foo/file
 git show --color HEAD -- foo/file
 # Graphical browser
 gitk

What did you change

 # Lists you the revs that are only in your branch compared to org.openembedded.dev
 git rev-list origin/org.openembedded.dev..

Other Interesting commands

 # fetch new revisions from all remote repositories
 git fetch
 # show your local branches and which branch you are in
 git branch
 # show all branches
 git branch -a
 # create a branch and switch to it
 git checkout -b MYNAME origin/THEIRNAME
 # upgrade a branch
 git push origin org.openembedded.dev
 git reflog
 # Change your index to be at the state of REF
 git reset REF
 # Kill the last commit
 git reset HEAD^1
 # Prepare a set of patch
 git format-patch origin
 # What changes have I made
 git status
 # List details of those changes
 git diff --cached

Working with additional git repositories

One of the neat things with git is you can easily work with external repositories.

 # add an external repository:
 git remote add openmoko.org git://git.openmoko.org/git/openmoko.git
 git fetch openmoko.org
 
 # view all remote branches available
 git branch -r
 # view changes on a remote branch
 gitk openmoko.org/org.openmoko.asu.stable
 git log openmoko.org/org.openmoko.asu.stable
 # view all diffs
 git diff origin/org.openembedded.dev openmoko.org/org.openmoko.asu.stable
 
 # view diffs in just one subdirectory
 git diff origin/org.openembedded.dev openmoko.org/org.openmoko.asu.stable classes


Examples

Example 1:

 vi packages/gaim/gaim.inc
 git commit packages/gaim/gaim.inc
 git pull --rebase

should have a log message like this:

gaim: make sure do_install does its job in gaim.inc
* install lib to ${libdir} instead of /usr/lib
* remove executable bits from docs

Example 2:

diff /tmp/foo.c /oe/work/gtk+-2.8.4-r0/gtk+-2.8.4/src/foo.c > gtk-2.8.4/fix-foo.patch
vi gtk+_2.8.4.bb
git add gtk-2.8.4/fix-foo.patch
git commit gtk-2.8.4/fix-foo.patch gtk+_2.8.4.bb
git pull --rebase

should have a log message like this:

gtk+ 2.8.4: add patch for buffer overflow

Example 3: Working with a private branch

Download and create a remote private branch "origin/ulf/linux-2.6.39-2011-11-22". The local copy of the branch will be called "ulf/linux-2.6.39-2011-11-22". When you do:

git branch -a

local branches will be at the top, and remote branches will be sorted in alpabetical order.

Create the local branch and prepare:

git clone git@git.openembedded.org:openembedded
cd openembedded
git config user.name "Ulf Samuelsson"
git config user.email "ulf_samuelsson@telia.com"
git checkout -b ulf/linux-2.6.39-2011-11-22 origin/org.openembedded.dev

Add something:

touch test
git add test
git commit -m "test" test

Create a remote private branch from the local branch. It will be called "origin/ulf/linux-2.6.39-2011-11-22"

git push origin ulf/linux-2.6.39-2011-11-22

Create a local branch, based on your remote private branch:

git checkout -b ulf/linux-2.6.39-2011-11-22 origin/ulf/linux-2.6.39-2011-11-22

Add something to your local branch:

touch test2
git add test2
git commit -m "test2" test2

Update your remote private branch:

git push origin ulf/linux-2.6.39-2011-11-22

Once the remote branch has been updated from a local branch you need to update any other local branches by:

git fetch origin

Prepare patches for the mailing list:

git format-patch origin

Remove your local branch:

git checkout origin/org.openembedded.dev
git branch -d ulf/llinux-2.6.39-2011-11-22

or possibly:

git branch -D ulf/linux-2.6.39-2011-11-22

Note that the openembedded git server will not allow you to delete a private branch at this time. Send an email to the mailing list and this will be fixed.