External Use
TM
Linux GIT Software Overview
FTF-SDS-F0248
A P R . 2 0 1 4
Richard Schmitt
TM
External Use 1
Scope
• Learn more about the Linux GIT software repositories, source
control basics, cloning repositories, editing files and committing
changes, synchronizing repositories, and merging.
• Also, learn about Gerrit as a workflow and change review tool and
how we use it for the QorIQ SDK release process.
TM
External Use 2
Agenda
• Welcome
• Basic GIT Concepts
• Working with GIT
• Collaborating with GIT
• Branching and Merging
• Command Summary
• Gerrit
• Freescale Repositories
• Advanced Usage
• Questions and Answers
TM
External Use 3
Basic GIT Concepts
TM
External Use 4
Git Basic Concepts
• Git is a distributed Version Control System (VCS)
− Originally created for the Linux kernel in 2005
− As opposed to a centralized VCS, each developer has a
complete, local repository, “cloned” from an “official” remote
repository
− The “official” repository can be updated from local repositories
by “pushing” the latest state of a local repository to the
“official” repository
Typically only the “official” repository maintainers can do that
Other developers submit patches for review to the maintainers
− Developers can synchronize their local repositories with the
“official” repository, by “pulling” the latest state from the
“official” repository to the local repository
TM
External Use 5
Git Basic Terms
• Repository − Version control database that stores multiple revisions of a source tree
(code base) and their associated metadata
− “.git” subdirectory in the top-level directory of a source tree that is
under Git version control
• Commit
− Represents a revision of a source tree stored in the repository
− It is a “snapshot” of the whole source tree, stored in the repository
− Identified by a 160-bit unique identifier (SHA1)
A hash from the content of the snapshot
Displayed a 40-digit hexadecimal number
− A commit SHA1 can be seen as a pointer to a source tree snapshot
− Examples of Git commands that create commits:
git commit, git merge, git cherry-pick
TM
External Use 6
Git Basic Terms (continued)
• Commit (continued)
− Each commit points to one or more parent commits
Predecessor “snapshots” in the revision history of the source tree
− Every commit is a full snapshot of the whole project
− Git optimizes storage, will not create copies of non-modified files
(picture from “Git/Gerrit Workshop”, http://gerrit-training.scmforge.com/git-gerrit-workshop.html)
TM
External Use 7
Git Basic Terms (continued)
• Branch
− A movable pointer (“ref” in Git terms) that points to a given commit in a
repository
Like a symbolic link that contains the SHA1 of the given commit
− The commit SHA1 pointed to by the branch represents the latest revision
of the source tree on a given line of development, represented by the chain
of predecessor commits
− There is a default branch named “master,” if no branches are created explicitly
− For a given commit to be accessible, either a branch needs to point to it, or
another commit needs to point to it in a predecessor chain (unless you know its
SHA1)
Commits that are not pointed to by any ref are eventually garbage-collected by Git
Since the last commit is not the predecessor of any other commit, a branch or tag needs
to point to it, otherwise it will get garbage-collected by Git
TM
External Use 8
Git Basic Terms (continued)
• Branch (continued)
− A branch is implemented as a file that contains the SHA1 of a given
commit
− Example: the “master” branch is stored as file “.git/refs/heads/master”
$ cat .git/refs/heads/master
5674c0051c6086c8db46dee88f1f53fcf0c9137f
− To create a new branch do:
$ git branch <branch name>
By default, the new branch will initially point to
the same commit as the current branch
(picture from “Git/Gerrit Workshop”,
http://gerrit-training.scmforge.com/git-gerrit-workshop.html)
TM
External Use 9
Git Basic Terms (continued)
• Current Branch
− A repository always has a current branch (except in “detached head
mode”)
− In a newly-created repository, the current branch is “master”
− To set the current branch to a different branch do “git checkout”:
$ git checkout <branch name>
− The current branch is represented by a special ref named “HEAD”
HEAD is like a symbolic link that contains the name of the current branch
To display the current branch, use the “git branch” command
− A new commit is typically created in the context of the current branch of a
repository
Every time that a new commit is created in the repository, the current branch “ref” is
moved to point to the SHA1 of the new commit
TM
External Use 10
Git Basic Terms (continued)
• Current Branch (continued)
− When a new commit is created, the
current branch is updated to point to it
Implicitly HEAD is also moved, since it is a
“symbolic link” for the current branch
− Example of creating a new
commit, assuming that “master”
is the current branch:
Before the new commit, branch “master”
points to commit “C”
After the new commit, branch “master” points
to commit “D”
(picture from “Git/Gerrit Workshop”,
http://gerrit-training.scmforge.com/git-gerrit-workshop.html)
HEAD
HEAD
TM
External Use 11
Git Basic Terms (continued)
• Current Branch (continued)
− Example of setting the current branch to a different branch:
(picture from “Git/Gerrit Workshop”, http://gerrit-training.scmforge.com/git-gerrit-workshop.html)
git checkout bugfix15
before after
TM
External Use 12
Git Basic Terms (continued)
• Tag
− A fixed pointer (“ref” in Git terms) that points to a given commit in a repository Once created, a tag always points to the same commit
• Working Tree − Currently “checked-out” revision of the source tree stored in a Git repository: Source tree snapshot (commit) currently extracted from the repository,
as a hierarchy of directories/files
− Side effect of the “git checkout” command: The source tree snapshot for the corresponding commit is retrieved from the
repository and overwrites the working tree
− Files can be modified, added or removed from the working tree and then a new commit can be done to create a new source tree snapshot in the repository
• Index − Staging area for working tree changes to be included in the next commit Only changes “added” to the index will be included in the next commit
− Useful to split changes to the same working tree into multiple commits (patches)
TM
External Use 13
Git Basic Terms (continued)
• Remote
− An “alias” for the URL of a remote repository
− A remote named “origin” is created when a remote repo is cloned
− Other remotes can be add with the “git remote add” command
• Remote Branch
− A branch of the form <remote>/<branch>
• Tracking Branch
− Local branch that tracks a branch with the same name on a remote repository
− Checking out a local branch that does not exist locally but that exists in a remote, creates a tracking branch
− Used by git pull and git push to determine the branch in the remote
• Submodule
− A submodule allows you to keep a Git repository as a subdirectory of another Git repository
− A way to split a large code base into separate git repositories (submodules)
TM
External Use 14
Working with GIT
TM
External Use 15
Git Basic Repository Structure
Top-level directory of source tree
Source files and subdirectories (working tree)
.git subdirectory (actual repository) 24K .git/refs/heads
12K .git/refs/tags
36K .git/refs/remotes/origin
5.0M .git/objects
1.5G .git/modules
Linux kernel submodule 738M .git/modules/linux
32K .git/modules/linux/refs/heads
8.0K .git/modules/linux/refs/tags
40K .git/modules/linux/refs/remotes/origin
713M .git/modules/linux/objects
U-boot submodule 64M .git/modules/u-boot
8.0K .git/modules/u-boot/refs/heads
8.0K .git/modules/u-boot/refs/tags
20K .git/modules/u-boot/refs/remotes/origin
63M .git/modules/u-boot/objects
TM
External Use 16
How to Create a Git Repository
• Create a local Git repository by cloning an “official” remote
repository
$ git clone <remote Git repository URL>
− Examples: $ git clone git://git.am.freescale.net/gitolite/sdk/linux-devel.git
$ git clone ssh://gerrit.am.freescale.net/sdk/sdk-devel.git
• Create a stand-alone local Git repository in the current directory
− $ git init
• Create a “bare” Git repository (a repository without a working tree)
in a Git server
− $ git clone ––bare <URL of existing repository>
− $ git init --bare
TM
External Use 17
Local Git Workflows
• A workflow to modify existing files in a local repository
− Checkout target branch
$ git checkout
− Edit existing files
− Stage the changes
$ git add <files changed>
− Review your changes
$ git diff –staged HEAD
− Commit the changes
$ git commit
(Picture from “Pro Git”, by Scott Chacon
http://git-scm.com/book)
Index
TM
External Use 18
Local Git Workflows (continued)
• A workflow to modify existing files in a local repository, without
explicit staging
− Checkout target branch
$ git checkout
− Edit existing files
− Review your changes
$ git diff HEAD
− Commit all unstaged changes
(not including new files)
$ git commit -a
(Picture from “Pro Git”, by Scott Chacon
http://git-scm.com/book)
Automatic staging
done as part of
“git commit –a”
TM
External Use 19
Local Git Workflows (continued)
• A workflow to create new files in a local repository
− Checkout target branch
$ git checkout
− Create new files
− Add new files to index
$ git add <new files>
− Commit the changes
$ git commit
(Picture from “Pro Git”, by Scott Chacon
http://git-scm.com/book)
TM
External Use 20
Local Git Workflows (continued)
• A workflow to remove or rename
existing files in a local repository
− Checkout target branch
$ git checkout
− Remove files from working tree
and index
$ git rm <files>
− Rename files in working tree and
index
$ git mv <files>
− Commit the changes
$ git commit
(Picture from “Pro Git”, by Scott Chacon
http://git-scm.com/book)
TM
External Use 21
Local Git Workflows (continued)
• Undoing uncommitted changes
− Undoing all uncommitted changes from working tree and from index
$ git reset –hard HEAD
Resets both the working tree and the index to match the source tree snapshot of the commit pointed to by the current branch (branch pointed to by HEAD)
− Undoing uncommitted changes to a specific file
$ git checkout <file path>
Restore file in the working tree and index from the source tree snapshot of the
commit pointed to by the current branch
− Switch to another branch discarding all uncommitted changes for the
current branch
$ git checkout –force <branch name>
TM
External Use 22
Local Git Workflows (continued)
• Undoing committed changes
− Undoing the last commit
$ git reset –hard HEAD^
Resets both the working tree and the index to match the source tree snapshot of the predecessor commit for the commit pointed to by the current branch
− Undoing the last n commits
$ git reset –hard HEAD~n
− Reverting a given commit in the middle of the predecessor chain for the
current branch
$ git revert <commit SHA1>
Creates a new commit on the current branch that reverses the effect of the
given commit
TM
External Use 23
Collaborating with GIT
TM
External Use 24
Git server host
Git Distributed Model
• Developers have their own local repositories cloned from an “official”
remote repository
“Official” Git
Repository
“Local” Git
Repository
“Local” Git
Repository
git clone,
git fetch,
git pull
git clone,
git fetch,
git pull
..
TM
External Use 25
Git server host
Git Distributed Model (continued)
• Repository maintainers can update the “official” repository from
their local repositories
“Official” Git
Repository
“Local” Git
Repository
“Local” Git
Repository
git push
git push
..
TM
External Use 26
Distributed Git Workflows
• Cloning a remote repository $ git clone git://git.am.freescale.net/gitolite/sdk/linux-devel.git
− Locally the remote repo will be known as the remote alias “origin”
− Local branch “master” is a tracking branch
(picture from “Git/Gerrit Workshop”, http://gerrit-training.scmforge.com/git-gerrit-workshop.html)
Local branch
associated with a
branch of same
name on the remote
TM
External Use 27
Distributed Git Workflows (continued)
• Creating a new tracking branch $ git checkout <branch name from remote>
(picture from “Git/Gerrit Workshop”, http://gerrit-training.scmforge.com/git-gerrit-workshop.html)
Local branch
associated with a
branch of same
name on the remote
release1.0
git checkout release1.0
HEAD
Pointer to current
branch changed
TM
External Use 28
Distributed Git Workflows (continued)
• Fetching a remote repository (previously cloned) $ git fetch origin release1.0
− Remote branch “origin/release1.0” in the local repo is updated to match branch
“release1.0” in the remote “origin” repo
(picture from “Git/Gerrit Workshop”, http://gerrit-training.scmforge.com/git-gerrit-workshop.html)
Local branch
“release1.0”
is not changed
release1.0 HEAD
after fetch
before fetch
TM
External Use 29
Distributed Git Workflows (continued)
• Pulling from a remote repository (previously cloned) $ git pull origin release1.0
− Same as fetch but also, remote branch “origin/release1.0” is merged into local
branch “release1.0”
(picture from “Git/Gerrit Workshop”, http://gerrit-training.scmforge.com/git-gerrit-workshop.html)
after merge
(“fast forward” merge
in this case)
release1.0 HEAD
Pull = fetch + merge
after fetch
TM
External Use 30
Distributed Git Workflows (continued)
• Pushing to a remote repository (previously cloned)
− Example: Push the local branch “feature” to branch “master” in the
remote “origin”
$ git push origin feature:master
or
$ git push origin HEAD:master
(picture from “Git/Gerrit Workshop”, http://gerrit-training.scmforge.com/git-gerrit-workshop.html)
NOTE:
without “<source branch>:”
local branch “master” would be
pushed instead
TM
External Use 31
Branching
TM
External Use 32
Local Git Workflows with Multiple Branches
• Git merge – Case 1: fast-forward merge
− Example: Merge branch “feature1” to branch “master”
$ git checkout master
$ git merge feature1
(picture from “Git/Gerrit Workshop”, http://gerrit-training.scmforge.com/git-gerrit-workshop.html)
before after
git merge
TM
External Use 33
Local Git Workflows with Multiple Branches (continued)
• Git merge – Case 2: actual merge of two commit chains
− Example: Merge branch “feature1” to branch “master”
$ git checkout master
$ git merge feature1
(picture from “Git/Gerrit Workshop”, http://gerrit-training.scmforge.com/git-gerrit-workshop.html)
git merge
before
after with merge
conflicts resolved,
if any
TM
External Use 34
Local Git Workflows with Multiple Branches (continued)
• Git rebase: re-apply commits from “feature 1” since common
ancestor, on top of commit pointed to by “master”
$ git checkout feature1
$ git rebase master
before
This now
unreferenced
commit chain will
get garbage
collected
with merge
conflicts resolved,
if any
git rebase
(picture from “Git/Gerrit Workshop”, http://gerrit-training.scmforge.com/git-gerrit-workshop.html)
after
Rebase “feature1”
from “master”
TM
External Use 35
Local Git Workflows with Multiple Branches (continued)
• Git cherry-pick
− Example: Apply commit F on branch “master”
$ git checkout master
$ git cherry-pick <commit F>
before
(picture from “Git/Gerrit Workshop”, http://gerrit-training.scmforge.com/git-gerrit-workshop.html)
after
git cherry-pick
G points to the
same source tree
snapshot as F, but
has different
ancestor
TM
External Use 36
GIT Command Summary
TM
External Use 37
Commonly Used Commands
• git clone from the upstream to prime your local repository
• git pull and git fetch from "origin" to keep up-to-date with the
upstream
• git push to shared repository, if you adopt CVS style shared
repository workflow
• git branch (with no arguments) to see where you are
• git log to see what happened
• git whatchanged to find out where things have come from
• git checkout to switch branches (and create local tracking
branches)
• git add to stage changes and to add new files
• git remote to see the existing remotes for the local repo
TM
External Use 38
Commonly Used Commands (continued)
• git diff to see differences
• git status to see current state of working tree and index
• git commit to advance the current branch
• git reset and git checkout <pathname> to undo changes.
• git rebase to maintain topic branches
• git tag to mark known point
• git merge to merge another branch into the current branch
• git branch <branch name> to create a new branch starting at the
last commit on the current branch
• git cherry-pick to create a new commit on the current branch, that
duplicates a commit from another branch
• git revert to create a new commit that reverses the change from an
earlier commit on the current branch
TM
External Use 39
Gerrit
TM
External Use 40
Gerrit Basic Concepts
• Gerrit is Web-based code review
system integrated with Git
− It serves as front-end to “official”
(authoritative) Git repositories
− Developers can only push “for review”
− Only designated maintainers can push
to the “official” repositories
• It is also integrated with the Jenkins
continuous-integration tool
− It automatically builds each change
submitted for review
(picture from “Gerrit Code Review - A Quick Introduction”,
http://gerrit-documentation.googlecode.com/svn/Documentation/2.7/intro-quick.html)
TM
External Use 41
Gerrit Workflow
(picture from “Git/Gerrit Workshop”, http://gerrit-training.scmforge.com/git-gerrit-workshop.html)
Second and
further iterations of
the same change
must include the
Gerrit change Id of
the change
TM
External Use 42
Initial Push for Code Review
$ git commit
$ git push origin HEAD:refs/for/master
(picture from “Git/Gerrit Workshop”, http://gerrit-training.scmforge.com/git-gerrit-workshop.html)
Each iteration of a Gerrit
change consists of a
Gerrit “patch set,”
which corresponds to a
single Git commit A Gerrit “patch
set” is represented
by a Git branch
(commit pointer)
Remote “origin” repo in
Gerrit server
Gerrit change #
Iteration #
TM
External Use 43
Subsequent Push for Code Review
$ git commit –amend
$ git push origin HEAD:refs/for/master
(picture from “Git/Gerrit Workshop”, http://gerrit-training.scmforge.com/git-gerrit-workshop.html)
Really
git –amend + Gerrit magic
(change-Id commit-msg hook)
On the remote, after push,
commit D will be pointed to by:
refs/changes/35/135/2
TM
External Use 44
Gerrit Change Web Page
(picture from “Git/Gerrit Workshop”, http://gerrit-training.scmforge.com/git-gerrit-workshop.html)
Gerrit change #
Jenkins
build
succeeded
Gerrit change Id
All Git commits
(“patch sets”) that
are iterations of the
same Gerrit change
must have the same
change Id in the
commit message
TM
External Use 45
Push Multiple Changes
$ git push origin HEAD:refs/for/master
(picture from “Git/Gerrit Workshop”, http://gerrit-training.scmforge.com/git-gerrit-workshop.html)
Remote “origin” repo in
Gerrit server
• For each commit
from the local branch
not available in the
remote branch, a
different Gerrit
change gets created
• All these changes
are chained together
in a “depends on”
chain
TM
External Use 46
Working with Freescale Repositories
TM
External Use 47
Freescale SDK Git Repositories
• Public repositories
− Linux kernel repository
http://git.freescale.com/git/cgit.cgi/ppc/sdk/linux.git
− U-boot repository
http://git.freescale.com/git/cgit.cgi/ppc/sdk/u-boot.git/
− For other repositories see
http://git.freescale.com
• Internal repositories
− Linux kernel repository
http://git.am.freescale.net/gitolite/gitweb.cgi/sdk/linux-devel.git
− U-boot repository
http://git.freescale.com/git/cgit.cgi/ppc/sdk/u-boot.git
− For other repositories see
http://git.am.freescale.net
TM
External Use 48
Gerrit for Freescale SDK Repositories
• Gerrit Web page for internal SDK repositories
http://git.am.freescale.net
• Gerrit Web page for changes submitted for review
http://git.am.freescale.net:8181
• Jenkins Web page for Gerrit-triggered builds
http://busy.am.freescale.net/me/my-views/view/All/job/gerrit-linux-build-
for-submit
TM
External Use 49
Example of Tracking Down a Build Break
• Given the following Linux kernel build error: arch/powerpc/kernel/built-in.o: In function `setup_pw20_idle': (.text+0xb364): undefined reference to `.has_pw20_altivec_idle' arch/powerpc/kernel/built-in.o: In function `setup_altivec_idle': (.text+0xb390): undefined reference to `.has_pw20_altivec_idle' make[1]: *** [vmlinux] Error 1 …
• Find the commit that introduced the error $ git log -S "has_pw20_altivec_idle"
commit cf41f28c197342f10da49d5b71dec498b3434bc5
Author: Wang Dongsheng <[email protected]>
Date: Thu Sep 12 10:24:55 2013 +0800
powerpc/85xx: fix pw20&altivec idle can not work after cpuhotplug restore PW20 & AltiVec idle should be enabled, when the cpuhotplug restore. Signed-off-by: Wang Dongsheng <[email protected]> Change-Id: Ib4d2ac24eedde0a6a814f3b5f0b42ca03e20494c Reviewed-on: http://git.am.freescale.net:8181/4269
…
Gerrit change #
Gerrit change Id
Git commit SHA1
TM
External Use 50
Advanced Usage
TM
External Use 51
Example of Tracking Down a Build Break
• See what files got changed by the commit: $ git show --name-status cf41f28c197342f10da49d5b71dec498b3434bc5
commit cf41f28c197342f10da49d5b71dec498b3434bc5
…
M arch/powerpc/include/asm/reg_booke.h
M arch/powerpc/kernel/cpu_setup_fsl_booke.S
M arch/powerpc/platforms/85xx/common.c
• Examine the specific changes: $ git diff cf41f28c197342f10da49d5b71dec498b3434bc5 \
cf41f28c197342f10da49d5b71dec498b3434bc5^
TM
External Use 52
Example of Tracking Down a Build Break (continued)
• Confirm the culprit lines and who changed
them: $ git blame arch/powerpc/kernel/cpu_setup_fsl_booke.S
...
cf41f28c (Wang Dongsheng 2013-09-12 …) _GLOBAL(setup_pw20_idle)
cf41f28c (Wang Dongsheng 2013-09-12 …) mflr r10
cf41f28c (Wang Dongsheng 2013-09-12 …) bl .has_pw20_altivec_idle
cf41f28c (Wang Dongsheng 2013-09-12 …) mtlr r10
cf41f28c (Wang Dongsheng 2013-09-12 …) cmpwi r3, 0
cf41f28c (Wang Dongsheng 2013-09-12 …) beq 2f
...
TM
External Use 53
Example of Tracking Down a Build Break (continued)
• On what branches is this commit (in their
predecessor commit chains)? $ git branch --contains cf41f28c197342f10da49d5b71dec498b3434bc5
b4860rev2
master
sdk-kernel-3.8
sdk-v1.4.x
• On which branch was this commit originally
created? $ git-what-branch.pl --all cf41f28c197342f10da49d5b71dec498b3434bc5
b4860rev2
…
(script available at https://github.com/SethRobertson/git-what-branch)
TM
External Use 54
References
• http://git-scm.com/book
• http://gerrit-training.scmforge.com/git-gerrit-workshop.html
• http://www.kernel.org/pub/software/scm/git/docs
• https://www.kernel.org/pub/software/scm/git/docs/user-manual.html
• https://review.typo3.org/Documentation/intro-quick.htm
• http://gerrit-
documentation.googlecode.com/svn/Documentation/2.7/intro-
quick.html l
TM
External Use 55
Introducing The
QorIQ LS2 Family
Breakthrough,
software-defined
approach to advance
the world’s new
virtualized networks
New, high-performance architecture built with ease-of-use in mind Groundbreaking, flexible architecture that abstracts hardware complexity and
enables customers to focus their resources on innovation at the application level
Optimized for software-defined networking applications Balanced integration of CPU performance with network I/O and C-programmable
datapath acceleration that is right-sized (power/performance/cost) to deliver
advanced SoC technology for the SDN era
Extending the industry’s broadest portfolio of 64-bit multicore SoCs Built on the ARM® Cortex®-A57 architecture with integrated L2 switch enabling
interconnect and peripherals to provide a complete system-on-chip solution
TM
External Use 56
QorIQ LS2 Family Key Features
Unprecedented performance and
ease of use for smarter, more
capable networks
High performance cores with leading
interconnect and memory bandwidth
• 8x ARM Cortex-A57 cores, 2.0GHz, 4MB L2
cache, w Neon SIMD
• 1MB L3 platform cache w/ECC
• 2x 64b DDR4 up to 2.4GT/s
A high performance datapath designed
with software developers in mind
• New datapath hardware and abstracted
acceleration that is called via standard Linux
objects
• 40 Gbps Packet processing performance with
20Gbps acceleration (crypto, Pattern
Match/RegEx, Data Compression)
• Management complex provides all
init/setup/teardown tasks
Leading network I/O integration
• 8x1/10GbE + 8x1G, MACSec on up to 4x 1/10GbE
• Integrated L2 switching capability for cost savings
• 4 PCIe Gen3 controllers, 1 with SR-IOV support
• 2 x SATA 3.0, 2 x USB 3.0 with PHY
SDN/NFV
Switching
Data
Center
Wireless
Access
TM
External Use 57
See the LS2 Family First in the Tech Lab!
4 new demos built on QorIQ LS2 processors:
Performance Analysis Made Easy
Leave the Packet Processing To Us
Combining Ease of Use with Performance
Tools for Every Step of Your Design
TM
© 2014 Freescale Semiconductor, Inc. | External Use
www.Freescale.com