




已阅读5页,还剩22页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
C2 Git TrainingC2 microsystems, Beijing.Xinhe-Guo(revision 1,2,3,4,5,6)Content list1Tools installation31.1repo31.2git31.3ssh31.4git gui, graphics log and patch browser tool31.5Tig, a text based log/patch browser tool52Account setup52.1ssh52.2git53Repository url64Basic operation64.1Android project checkout from server64.2Update repo from server74.3Repo syntax list74.4Single git clone from server84.5Read Git info84.6Single git update from server84.7Git local commit84.8Git push back to server95Advanced operation95.1git log by date95.2git log single file95.3git log in repo range95.4git log compare 2 branchs105.5git log show all repos last modification105.6Get a daily repo log105.7Compare between branches105.8git rev-list105.9git blame115.10git show, read a logs patch115.11Git list a commits files115.12Git checkout115.13Switch among branch115.14Add remote to git115.15Git/repo checkout by date125.16git checkout by tag125.17Merge from another branch125.18Delete unexpected commits(from merge result)125.19Selected commit to merge125.20Create branch135.21Tag a single git135.22Tag a repo135.23Create new git project135.24Add new module to repo145.25Create new repo project145.26CVS project convert to git project145.27Short cut145.28git ops under repo, switch to non default remote branch156Git server management156.1Setup repo/git service156.2Setup mirror for repo/git service156.3Hook email156.4Hook post-receive166.5Hook pre-receive166.6Hook description176.7Setup the gitweb in apache server177Inside git177.1Git design overview177.2Git工作区、暂存区和版本库187.3Git objects197.4Inside a single git217.5Git diff227.6Git reset227.7Git checkout is HEAD reset237.8Git init237.9Git add237.10Git first commit247.11Add modified files247.12Add File into Subdirectory257.13Second Commit257.14Tag261 Tools installation1.1 repo download from /repo /bin/repo$ chmod a+x /bin/repoadd to system path export PATH=$PATH:/bin/repoor git clone git://tools/repo.gitcp repo/repo /usr/bin1.2 gitInstall git, using yum installOr get a copy source code, build and install1.3 sshInstall ssh1.4 git gui, graphics log and patch browser toolFor read git history directly, using “Repository/Visualize All Branch History”, this is help for understanding the codes history and modify ideas.If can not use gui, or via slow speed ssh, another method is using git log -graph. Example: git log -graph -pSnapshot of “git log -graph -oneline”1.5 Tig, a text based log/patch browser tool2 Account setup2.1 ssh Setup the ssh key, otherwise, every time need input password. A simple method to check your key is run “ssh 00”, if required a password, you need run next scripts: -f /.ssh/id_rsa | ( yes | ssh-keygen) ssh-copy-id -i /.ssh/id_rsa.pub $(whoami)002.2 gitRepo need know this.git config -global user.email $(whoami)git config -global $(whoami)This email and username will appear in git logs when you commit something to git. If not set properly, the git log will confuse other engineers.Result:cat /.gitconfig user email = name = hguo3 Repository urlAndroid project:ssh://mentor-mirror/build/manifests.git -b develSDK project(mostly is imported from CVS server)ssh://c2sdk/manifests.gitsw_media project(part of SDK project)ssh://c2sdk/manifests.git m sw_media.xmlsw_media project for ASIC team(part of SDK project)ssh://c2sdk/manifests.git m sw_media.hw.xmlAndroid branch project, include 2 repos:ssh://mentor-mirror/build/manifests.git -b jazz2t-0_2-1_Branchssh://c2sdk/manifests.git -b jazz2t-0_2-1_Branch m sw_media.xmlFor more of jazz2t-Android-0_3-1_Branch, ref: /index.php/Jazz2t-Android-0_3-1_BranchThere is a script that help clone all the things in one command: in your current android project home folder, find a build/tools/repobranch copy it to your target folder and execute it to get all the above things. enjoy the script. 4 Basic operation4.1 Android project checkout from serverSyntax: repo init -u url options . repo sync project-list Option for repo init.-b : Checkout manifest by branchssh://mentor-mirror/build/manifests.git -b devel-m : Checkout not the default manifests file:ssh://c2sdk/manifests.git -m fullgit.xmlExample: mkdir -p .repo;git clone ssh://mentor-mirror/build/repo.git .repo/reporepo init -u ssh://mentor-mirror/build/manifests.git -b devel repo sync repo start devel allQuick do repo init skill, this will not git clone repo from repos official server:if ! -d .repo ; thenmkdir -p .repo;pushd .repo;git clone ssh://mentor-mirror/build/repo.git;popd;firepo init -u ssh://mentor-mirror/build/manifests.git -b develrepo syncGet this script from android projects:build/tools/repo-init-sync-start-devel.sh4.2 Update repo from serverExample: repo sync repo start devel all4.3 Repo syntax listrepo init -u url options $ repo init -u git://platform/manifest.git To select a manifest file $ repo init -u git://platform/manifest.git -m dalkvik-plus.xml To specify a revision $ repo init -u git://platform/manifest.git -b release-1.0repo sync project-list repo forall project-list -c command arg.Using repo forall c”cmd list” to handle all gitsSyntax: Repo forall c “cmd1 args; cmd2 args*”repo start newbranchname project-list 4.4 Single git clone from serverExample:git clone ssh://mentor-mirror/build/manifests.gitExample:git clone :/mentor-mirror/build/manifests.git4.5 Read Git infogit branchgit remotegit statusgit show-refgit loggit log -graphgit guitig4.6 Single git update from serverExample:git pull $remote $branch4.7 Git local commitExample: git add .git commit m “write a meaningful summary here”4.8 Git push back to serverStep:O- git pull $remote $branchO- if no conflict, git push $remote $branch. O- if conflict, merge first, then re-commit. Go to first stepWarning:O- Never using git push without $remote $branch5 Advanced operation5.1 git log by dateSearch last a few hours commit for blame break/bugCheck a gits last a few hours modificationgit log -after=2011-04-26 00:00 5.2 git log single fileExample:git log -graph -follow -p filename -p This will display patch of each log -graph This will show the node relation ship in color-text based graphics. -follow This will show the entire history (including diffs for each change) of the file (including history beyond renames).In other words, if the file named bar was once named foo, then git log -p bar (without the -follow option) will only show the files history up to the point where it was renamed - it wont show the files history when it was known as foo. Using git log -follow -p bar will show the files entire history, including any changes to the file when it was known as foo5.3 git log in repo rangeCheck all repos last a few hours modificationrepo forall -c git log -after=2011-04-26 00:005.4 git log compare 2 branchsgit log -oneline -exit-code master -not devel5.5 git log show all repos last modificationvery useful.Command:repo forall -c echo $(git log -pretty=format:%at %ar - %an, %h: %s -n 1) $(pwd) | sort -routput:1322295488 3 hours ago - txiang, c489a70: Fixed the bug /packages/apps/C2Launcher2Format: %at %ar %an %h %s pwd5.6 Get a daily repo logrepo forall -c git log -n 3 -after=1 day ago /tmp/x; if stat -c %s /tmp/x -gt 0 ;then pwd;cat /tmp/x;echo;fi5.7 Compare between branchesgit log -oneline -exit-code $BR1 -not $BR2repo forall -p -c git log -oneline -exit-code $BR1 -not $BR2example:git log -oneline -exit-code master -not develrepo forall -p -c git log -oneline -exit-code c2micro-froyo -not devel5.8 git rev-listExample: git rev-list -n 1 develNote: This will list the ids of this git repository, not of the current work folder.For work folder, use: git log -n 1 | grep commit | sed s/commit /g5.9 git blameTo show what revision and author last modified each line of a filegit blame filename5.10 git show, read a logs patchExample:git show hash_id if no hash id, the top hash id is used as default.5.11 Git list a commits filesHow do I list all the files for a commit in gitThis should get you a little closer to your goal.$ git show -pretty=format: -name-only bd61ad985.12 Git checkoutCheckout by hash id: git checkout Checkout by branch:git checkout $BRANCH5.13 Switch among branchExample:git checkout $BRANCH5.14 Add remote to git$ git remote add repo git://tools/repo.git$ git pull repo stableThis will add to .git/configremote repo url = git://tools/repo.git fetch = +refs/heads/*:refs/remotes/repo/*5.15 Git/repo checkout by dateExample checkout a version before a date/time: git checkout git rev-list -n 1 -before=2011-03-27 13:37 develExample checkout full version before a date/time: repo forall -c git checkout $(git rev-list -n 1 -before=2011-03-27 13:37 devel)5.16 git checkout by tagExample checkout a version of tag v1.0.0 git checkout v1.0.05.17 Merge from another branchExample: git merge $ANOTHER_BRANCH_NAME5.18 Delete unexpected commits(from merge result)If you merge too much than your expected, pick some one to delete but want to keep the history: Using Git revert $ID This will create another commit, the result is the $IDs patch is removed from repository.5.19 Selected commit to mergeGit/Pull a single commit from another branchgit cherry-pick $IDThis will reuse the commits patch, but create another commit ID.If branch BR1 has commit a b c d e f g, and, want to merge b d f to branch BR2, and keep the commit ID, thats impossible!Useful case:BR1: a b c d e f g h I j k l m n o p q r s t u v w x y zWant: merge b d f, using cherry-pitch Want: merge a b c d e f g h I j k l n o p q r s t u v w x y z, using merge, then revert m5.20 Create branchExample: git branch $NEW_BRANCH_NAMEIf need push to server: git push $REMOTE $NEW_BRANCH_NAMEfor all repo, using repo forall -c git branch $NEW_BRANCH_NAME repo forall -c git push $REMOTE $NEW_BRANCH_NAME5.21 Tag a single gitExample:git tag -m auto tag on Ymdtag Ymdtag;git push -tags c2 devel;5.22 Tag a repoExample:repo forall -c git tag -m auto tag on $Ymdtag $Ymdtag;git push -tags c2 devel;A better script:repo forall -c git tag | grep $Ymdtag /dev/null; if $? -eq 0 ; then echo $PWD already tagged with id: $Ymdtag; else echo $PWD still not tag $Ymdtag; git tag -m auto tag on $Ymdtag $Ymdtag; git push -tags c2 $BR;fi5.23 Create new git projectExample:git initgit add .git commit -m git init repo on hostname by whoami, date5.24 Add new module to repoServer side:git clone bare basic-git-repositoryadd to manifestsClient side:repo syncrepo start $BR -all5.25 Create new repo projectCreate a bare git that include a manifestAdd other git-repository to the mainfest5.26 CVS project convert to git projectBetter use git =1.7.4, and cvsps =2.2.bExample:git cvsimport -v -a -k -d /db/cvsroot -C linux-2.6.23 projects/sw/kernel/linux-2.6Sepcial scan example, the -p will pass parameter from cvsimport to cvsps:git cvsimport -v -a -k -d $CVSROOT -p -d,$year/01/01 00:00:00,-d,$(year+1)/01/01 00:00:00,-b,HEAD -C media-$year projects/sw/media media-$year.log 2&1Advanced scan example, used for update the scaned git from cvs daily update:cvsps -q -Z 9 -d $datestart -d $datestop $cvsmodule $cvsps 2$log/$gitmodule.loggit cvsimport -v -a -k -d $CVSROOT -P $cvsps -C $gitmodule $cvsmodule $log/$gitmodule.log 2&15.27 Short cut# 设置快捷方式git config -global alias.ci commit git config -global alias.co checkout git config -global alias.br branch git config -global alias.lo log -color git config -global alias.sh show colorResult:cat /.gitconfig alias ci = commit co = checkout br = branch lo = log sh = show5.28 git ops under repo, switch to non default remote branchif default branch is master, switch to jazz2t-Android-0_2-1_Branch under sw_media/media, Do not use:git checkout jazz2t-Android-0_2-1_Branchthis will pull master to this branch and cause lots of merge errors.Use:Git checkout f c2/jazz2t-Android-0_2-1_Branch6 Git server management6.1 Setup repo/git serviceIn the folder that contains the bare gits, create a bare manifests.git for it. In the server, install the git software to system, default is in /usr/bin/. Without the system level git software, the git server can not bring up correctly via ssh service.6.2 Setup mirror for repo/git service.repo/repo/repo init -mirror u url b branch m yourmanifest.xmlRepo sync6.3 Hook emailThe .git/config include the remote info, email hook, etc.Step 1: add hook config to .git/confighooks mailinglist = cvs_change_sw_ announcelist = envelopesender = emailprefix = Gitstep 2: enable hook script in .git/hookscd .git/hookscp post-receive.sample post-receiveremote “#” in last line in this script6.4 Hook post-receiveAdd mailinglist to xxx.git/config if not set yet, examplehooks mailinglist = android_ announcelist = envelopesender = emailprefix = GitAdd hook to xxx.git/hooks/post-receive#!/bin/sh. /usr/share/doc/git-core/contrib/hooks/post-receive-emailGet the post-receive-email from stand git official release.6.5 Hook pre-receiveAdd mailinglist to xxx.git/config if not set yet, refer hook post-receiveAdd config item to xxx.git/configpush policy = user preset = enablepush user preset = disable disable = root enable = hguopush master preset = disable disable = root enable = hguoProcess flowchart 1.support only git config push.policy is user, if not set, default to user2. Get basic setting from git config push.preset, if not set, default to enableThen for user level control1. if exist git config push.user.preset, overwrite the permit.2. if user in git config push.user.enable list, overwrite the permit to enable3. if user in git config push.user.disable list, overwrite the permit to disableThen for branch level control1. if exist git config push.branch.preset, overwrite the permit.2 if user in git config push.branch.enable list, overwrite the permit to enable3. if user in git config push.branch.disable list, overwrite the permit to disableAdd hook to xxx.git/hooks/pre-receive#!/bin/sh. /usr/share/doc/git-core/contrib/hooks/pre-receive-emailThe pre-receive-email is modified from post-receive-email, will execute the previous defined process flowchart, if permit is disable, send email and exit 1 to block gits push operation.6.6 Hook descriptionUpdate the .git/description, put a brief description instead the original information.6.7 Setup the gitweb in apache serverTurn to the IT for more help.7 Inside gitThanks to: 1Gi权威指南一书由机工华章于 2011年6月出版,作者是 北京群英汇信息技术有限公司 高级顾问 蒋鑫。注意本书是原创,不是翻译的哦。/doc/gotgit//doc/gotgit-en/2/2011/05/learning-git-internals-by-example7.1 Git design overviewDo not use git commit -a7.2 Git工作区、暂存区和版本库 首先明白,.git/index实际上就是一个包含文件索引
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 教师招聘之《幼儿教师招聘》考前冲刺测试卷附有答案详解含答案详解【a卷】
- 教师招聘之《幼儿教师招聘》考试彩蛋押题含答案详解(综合卷)
- 2025一建《水利水电工程管理与实务》考前十页纸(填空版)
- 教师招聘之《小学教师招聘》题库(得分题)打印附参考答案详解【a卷】
- 微某著名企业
- 教师招聘之《幼儿教师招聘》强化训练附参考答案详解(精练)
- 教师招聘之《幼儿教师招聘》强化训练题型汇编及完整答案详解一套
- 押题宝典教师招聘之《幼儿教师招聘》模考模拟试题含答案详解【培优a卷】
- 押题宝典教师招聘之《小学教师招聘》通关考试题库附答案详解(预热题)
- 教师招聘之《小学教师招聘》能力提升题库及答案详解【夺冠系列】
- 2025年中国物流集团国际物流事业部招聘面试经验及模拟题集
- 乡镇安全培训课件
- 2025年航空业面试者必看航空公司招聘笔试预测试题及答案
- 2025年全国企业员工全面质量管理知识竞赛题及参考答案
- 2025年秋季开学典礼诗歌朗诵稿:纪念抗战胜利八十周年
- 2025秋仁爱科普版(2024)七年级上册英语教学计划
- 《非物质文化遗产概论(第三版)》全套教学课件
- 2025年广东省中考英语试卷深度评析及2026年备考策略
- 2025年信息安全应急演练记录
- 社区医院创建汇报课件
- 轴对称及其性质第1课时课件2025-2026学年人教版数学+八年级上册
评论
0/150
提交评论