当前位置:文档之家› git常用命令解释

git常用命令解释

GIT ANG REPOUSAGE1 git command1.1 git add∙git add . #将文件先暂存到staging area, stages new and modified, without deleted∙git add -A #states all∙git add -u #states modified and deleted, without new∙git add -i #进入互动模式∙git add filename #新增一个文件∙git add modify-file #修改过得文档也要加add,不然在commit时要加-a 1.2 git rm #删除文件∙git rm filename1.3 git mv #修改文件名,或搬移目录∙git mv filename newfilename1.4 git status #查看状态1.5 git commit∙git commit∙git commit -m 'commit message'∙git commit -a -m "message"∙git commit -a -v #-v查看修改的内容1.6 git branch∙git branch #列出所有的分支∙git branch new-branch #产生新的分支∙git branch new-branch master #由master产生新的分支∙git branch -d branch #删除分支∙git branch -D branch #强制删除分支∙git checkout -b new-branch #产生新分支并切换过去∙git branch -r #列出所有repository branch∙git branch -a #列出所有分支1.7 git checkout∙git checkout branch-name #切换到branch-name∙git checkout master #切换到master∙git checkout -b new-branch master #从master建立新的分支,并切换过去∙git checkout -b new-branch #由当前分支建立新分支∙git checkout -b new-branch origin #由origin建立分支∙git checkout filename #还原状态到repository状态∙git checkout HEAD . #将所有文件都checkout出来∙git checkout xxxx . #xxxx是commit的编号的前四位,将xxxx编号的版本checkout出来∙git checkout – * #恢复上一次commit的状态1.8 git diff∙git diff master #与master对比看哪些文件不同∙git diff –cached #比较staging area与repository∙git diff tag1 tag2 #tag1与tag2比较∙git diff tag1:file1 tag2:file2 #tag1的file1与tag2的file2比较∙git diff #当前与staging area比较∙git diff HEAD #当前与repository比较∙git diff new-brach #当前与new branch的比较∙git diff –stat1.9 git tag∙git tag v1 ebff #为commit ebff810c462234433434323334343设置标记v1 ∙git tag 版本1 ebff #tag可以为中文∙git tag -d 版本1 #删除标记版本11.10 git log∙git log #列出所有log∙git log –all∙git log -p #列出log及修改的内容∙git log -p filename #将filename的log及修改内容列出来∙git log –name-only #列出哪些文件被修改∙git log –stat –summary #列出各个版本间的改动及行数∙git log filename #这个文件的所有log∙git log directory #这个目录的所有log∙git log -S'FUNC()‘ #列出由FUNC()这个字符串的log∙git log –no-merges #不要列出merge的log∙git log –since="2 weeks ago" #列出最后两周的log∙git log –pretty=oneline∙git log –pretty=short1.11 git show∙git show ebff #显示commit ebff810xxxxxxxxxxx的内容∙git show v1 #显示tag v1的修改内容∙git show v1:hello.txt #显示tag:v1的hello.txt文件修改内容∙git show HEAD #当前版本的修改文件∙git show HEAD^ #前一版本所有修改的文件∙git show HEAD~4 #前4版本的修改文件1.12 git reset∙git reset –hard HEAD^ #还原到前一版本∙git reset –soft HEAD~31.13 git grep∙git grep "hello" v1 #查找tag:v1中是否由“hello"字符串∙git grep "hello"1.14 git stash∙git stash #放进暂存区∙git stash list #列出暂存区的文件∙git stash pop #取出最新的一笔,并移除∙git stash apply #取出但不移除∙git stash clear #清除暂存区1.15 git merge∙git merge #合并1.16 git blame∙git blame filename #列出此文件所有commit的记录1.17 git ls-files∙git ls-files -d #查看已删除的文件∙git ls-files -d | xargs git checkout – #将已删除的文件还原1.18 git revert∙git revert HEAD #回到前一此commit的状态∙git revert HEAD^ #回到上上一次的状态1.19 git remote∙git remote∙git remote add new-branch /project.git #增加远程repository的branch∙git remote show #列出现在由多少repository∙git remote rm new-branch #删除服务器上的新分支∙git remote update #更新所有repository branch1.20 git fetch∙git fetch origin1.21 git push∙git push origin:heads/xxx-branch2 repo command2.1 repo init∙repo init -u URL #在当前目录安装repo,该命令创建一个.repo文件夹,文件夹中包含一些git仓库,这些仓库包含着repo源代码何manifest文件。

++ -u:制定一个获取manifest仓库的URL。

++ -m:选择一个仓库中的manifest,默认是default.xml ++ -b:制定一个版本,也就是一个特别的manifet-branch2.2 repo sync∙repo sync [PROJECT LIST] #下载新的改变和更新当前目录下的工作文件,该命令相当与git remote update;git rebase origin/BRANCH (BRANCH本地分支)++ -d:将制定工程切换到特定的manifest版本++ -s:同步当前工程到一个由manifet-server元素指定的可编译的版本++ -f:继续同步其他工程,即使有错误发生2.3 repo upload∙repo upload [PROJECT LIST] #上传修改的代码2.4 repo diff∙repo diff [PROJECT LIST]2.5 repo download∙repo download target revision #下载特定的版本到本地2.6 repo forall∙repo forall -c command #对每一个项目执行command2.7 repo foreach∙repo foreach [project list】-c command #对project执行command 2.8 repo start∙repo start newbranchname . #创建一个新分支2.9 repo prune∙repo prune [project list] #删除已经merge的project2.10 repo status∙repo status #显示每个仓库的状态3 创建本地repo服务器∙mkdir repositories∙cd repositories∙git init –bare manifest.git∙git init –bare project1.git∙git init –bare project2.git∙cd -∙mkdir myrepo∙cd myrepo∙git clone /path/to/manifest.git∙cd manifest∙create a default.xml file with following content:<?xml version="1.0" encoding="UTF-8"?><manifest><remote name="korg" fetch="/path/to/repositories/" review="" /><default revision="master" remote="korg" /><project path="project1" name="project1" /><project path="project2" name="project2" /></manifest>∙git add –all∙git commit -a -m "add defalut.xml"∙git push –all∙cd ..∙git clone /path/to/project1.git∙cd project1∙echo "hello project1" > hello.txt∙git add -all∙git commit -a -m “add hello.txt in project1"∙git push -all∙cd ..∙git clone /path/to/project2.git∙cd project2∙echo "hello project2" > hello.txt∙git add -all∙git commit -a -m "add hello.txt in project2"∙git push -all∙cd ../..∙mkdir myproject∙cd myproject∙repo init -u /path/to/manifet.git∙repo syncrepo logDate: 2012-05-05 六Author: Yanqing LiOrg version 7.8.11 with Emacs version 24 Validate XHTML 1.0。

相关主题