Changes between Version 20 and Version 21 of Developer/Git

Jan 19, 2012, 12:03:45 AM (9 years ago)

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


  • Developer/Git

    v20 v21  
    5252We can checkout one of those remote branches (e.g. rtems-4.10 branch) using the command:
    54  git checkout -b rtems410 origin/rtems-4-10-branch
     54 git checkout -b rtems410 origin/4.10
    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:// The 'git branch' command prints a list of the current local branches, indicating the one currently checked out.
    6767This command will update all your local branches with any new code revisions available on the central repository.
     68= Making Changes =
     70Git allows you to make changes in the RTEMS source tree and track those changes locally. First you need to clone the repository:
     72 git clone git:// rtems
     74Or if you already cloned it before, then you might want to update to the latest version before making your changes:
     76 cd rtems
     77 git pull
     79Next make your changes to files. If you add or delete files you need to inform Git
     81 git add /some/new/file
     82 git rm /some/old/file
     84When you're satisfied with the changes you made, commit them (locally)
     86 git commit -a
     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.
     90 git add /some/changed/files
     91 git commit
     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 =
     96Branches facilitate trying out new code and creating patches.
     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:
     100 git branch -r
     102Then checkout the desired remote branch, for example:
     104 git checkout -b rtems410 origin/4.10
     107Or if you have previously checked out the remote branch then you should see it in your local branches:
     109 git branch
     111You can change to an existing local branch easily:
     113 git checkout rtems410
     116You can also create a new branch and switch to it:
     118 git branch temporary
     119 git checkout temporary
     121Or more concisely:
     123 git checkout -b temporary
     126If you forget which branch you are on
     128 git branch
     130shows you by placing a * next to the current one.
     132When a branch is no longer useful you can delete it.
     134 git checkout master
     135 git branch -d temporary
     137If you have unmerged changes in the old branch git complains and you need to use -D instead of -d.
     138= Viewing Changes =
     141To view all changes since the last commit:
     143 git diff HEAD
     146To view all changes between the current branch and another branch, say master:
     148 git diff master..HEAD
     151To view descriptions of committed changes:
     153 git log
     155Or view the changeset for some file (or directory):
     157 git log /some/file
     160To view the changesets made between two branches:
     162 git log master..HEAD
     164Or for a more brief description use shortlog:
     166 git shortlog master..HEAD
     168= Reverting Changes =
     171To remove all (uncommitted) changes on a branch
     173 git checkout -f
     175Or to selectively revert (uncommited) files
     177 git checkout -- /some/file
     178 git checkout HEAD /some/file
     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.
     183 git reset HEAD-1
     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.
     187 git revert HEAD~1
     189Does the same as reset but creates a new commit with the reverted changes instead of modifying the local repository directly.
     190= Merging Changes =
     192Suppose you commit changes in two different branches, branch1 and branch2, and want to create a new branch containing both sets of changes:
     194 git checkout -b merged
     195 git merge branch1
     196 git merge branch2
     199Or you might want to bring the changes in one branch into the other:
     201 git checkout branch1
     202 git merge branch2
     205And now that branch2 is merged you might get rid of it:
     207 git branch -d branch2
     209= Creating a Patch =
     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.)
     213 git diff master..HEAD > ../rtems.diff
     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.
     217 git format-patch master
     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
     221 git config --global "Your Name"
     222 git config --global
     225See the [wiki:Bugzilla Bugzilla] page for information about submitting patches to RTEMS.
    68226=  GIT Access for contributors  =