Changes between Version 20 and Version 21 of Developer/Git


Ignore:
Timestamp:
Jan 19, 2012, 12:03:45 AM (9 years ago)
Author:
Gedare
Comment:

/* GIT Access for users */ Add some more useful examples of working with git.

Legend:

Unmodified
Added
Removed
Modified
  • Developer/Git

    v20 v21  
    5252We can checkout one of those remote branches (e.g. rtems-4.10 branch) using the command:
    5353{{{
    54  git checkout -b rtems410 origin/rtems-4-10-branch
     54 git checkout -b rtems410 origin/4.10
    5555}}}
    5656This will create a local branch named "rtems410", containing the rtems-4.10 release, that will track the remote branch "rtems-4-10-branch" in origin (git://git.rtems.org/rtems.git). The 'git branch' command prints a list of the current local branches, indicating the one currently checked out.
     
    6666}}}
    6767This command will update all your local branches with any new code revisions available on the central repository.
     68= Making Changes =
     69
     70Git allows you to make changes in the RTEMS source tree and track those changes locally. First you need to clone the repository:
     71{{{
     72 git clone git://git.rtems.org/rtems.git rtems
     73}}}
     74Or if you already cloned it before, then you might want to update to the latest version before making your changes:
     75{{{
     76 cd rtems
     77 git pull
     78}}}
     79Next make your changes to files. If you add or delete files you need to inform Git
     80{{{
     81 git add /some/new/file
     82 git rm /some/old/file
     83}}}
     84When you're satisfied with the changes you made, commit them (locally)
     85{{{
     86 git commit -a
     87}}}
     88The -a flag commits all the changes that were made, but you can also control which changes to commit by individually adding files as you modify them by using. You can also specify other options to commit, such as a message with the -m flag.
     89{{{
     90 git add /some/changed/files
     91 git commit
     92}}}
     93But you shouldn't do any of this on the branch that you cloned, instead you should create a new branch to work with, so that the cloned branch (master) is a pristine copy of the upstream RTEMS repository.
     94= Working with Branches =
     95
     96Branches facilitate trying out new code and creating patches.
     97
     98Previous release of RTEMS are available through remote branches. To check out a remote branch, first query the Git repository for the list of branches:
     99{{{
     100 git branch -r
     101}}}
     102Then checkout the desired remote branch, for example:
     103{{{
     104 git checkout -b rtems410 origin/4.10
     105}}}
     106
     107Or if you have previously checked out the remote branch then you should see it in your local branches:
     108{{{
     109 git branch
     110}}}
     111You can change to an existing local branch easily:
     112{{{
     113 git checkout rtems410
     114}}}
     115
     116You can also create a new branch and switch to it:
     117{{{
     118 git branch temporary
     119 git checkout temporary
     120}}}
     121Or more concisely:
     122{{{
     123 git checkout -b temporary
     124}}}
     125
     126If you forget which branch you are on
     127{{{
     128 git branch
     129}}}
     130shows you by placing a * next to the current one.
     131
     132When a branch is no longer useful you can delete it.
     133{{{
     134 git checkout master
     135 git branch -d temporary
     136}}}
     137If you have unmerged changes in the old branch git complains and you need to use -D instead of -d.
     138= Viewing Changes =
     139
     140
     141To view all changes since the last commit:
     142{{{
     143 git diff HEAD
     144}}}
     145
     146To view all changes between the current branch and another branch, say master:
     147{{{
     148 git diff master..HEAD
     149}}}
     150
     151To view descriptions of committed changes:
     152{{{
     153 git log
     154}}}
     155Or view the changeset for some file (or directory):
     156{{{
     157 git log /some/file
     158}}}
     159
     160To view the changesets made between two branches:
     161{{{
     162 git log master..HEAD
     163}}}
     164Or for a more brief description use shortlog:
     165{{{
     166 git shortlog master..HEAD
     167}}}
     168= Reverting Changes =
     169
     170
     171To remove all (uncommitted) changes on a branch
     172{{{
     173 git checkout -f
     174}}}
     175Or to selectively revert (uncommited) files
     176{{{
     177 git checkout -- /some/file
     178 git checkout HEAD /some/file
     179}}}
     180
     181To remove commits there are two useful options, reset and revert; revert is cleaner, and is the right way to revert changes that have already been pushed/pulled remotely.
     182{{{
     183 git reset HEAD-1
     184}}}
     185Removes the last 1 (or any other number you put) commit from the current branch. git reset should only be used on local branches that no one else is accessing remotely.
     186{{{
     187 git revert HEAD~1
     188}}}
     189Does the same as reset but creates a new commit with the reverted changes instead of modifying the local repository directly.
     190= Merging Changes =
     191
     192Suppose you commit changes in two different branches, branch1 and branch2, and want to create a new branch containing both sets of changes:
     193{{{
     194 git checkout -b merged
     195 git merge branch1
     196 git merge branch2
     197}}}
     198
     199Or you might want to bring the changes in one branch into the other:
     200{{{
     201 git checkout branch1
     202 git merge branch2
     203}}}
     204
     205And now that branch2 is merged you might get rid of it:
     206{{{
     207 git branch -d branch2
     208}}}
     209= Creating a Patch =
     210
     211The easiest way to create a patch is to make and commit changes in a branch and then use either diff or format-patch comparing against the upstream master branch. (Of course, if the patch is supposed to be against a different branch then you should substitute that branch's name for master.)
     212{{{
     213 git diff master..HEAD > ../rtems.diff
     214}}}
     215Creates a diff containing the changes made in the current branch's commits since the master branch. Here I redirected the output to a file in the parent directory.
     216{{{
     217 git format-patch master
     218}}}
     219Creates a separate patch for each commit that has been made between the master branch and the current branch's head. These files, appended with .patch, are formatted so they can be emailed and rely on having git configured with your name and email address, for example
     220{{{
     221 git config --global user.name "Your Name"
     222 git config --global user.email name@domain.com
     223}}}
     224
     225See the [wiki:Bugzilla Bugzilla] page for information about submitting patches to RTEMS.
    68226=  GIT Access for contributors  =
    69227