admin 管理员组文章数量: 1086019
2024年2月18日发(作者:jsp成品网站)
GIT ANG REPO
USAGE
1 git command
1.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 filename
1.3 git mv #修改文件名,或搬移目录
git mv filename newfilename
1.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 #由
git branch -d branch #删除分支
git branch -D branch #强制删除分支
git checkout -b new-branch #产生新分支并切换过去
git branch -r #列出所有master产生新的分支
repository branch
git branch -a #列出所有分支
1.7 git checkout
git checkout branch-name #切换到
git checkout master #切换到branch-name
master建立新的分支,并切换过去
master
git checkout -b new-branch master #从
git checkout -b new-branch #由当前分支建立新分支
git checkout -b new-branch origin #由
git checkout filename #还原状态到origin建立分支
checkout出来
repository状态
git checkout HEAD . #将所有文件都
git checkout xxxx . #xxxx是commit的编号的前四位,将xxxx编号的版commit的状态
本checkout出来
git checkout – * #恢复上一次1.8 git diff
git diff master #与master对比看哪些文件不同
staging area与repository
与tag2比较
的file1与tag2的file2比较
git diff –cached #比较
git diff tag1 tag2 #tag1
git diff tag1:file1 tag2:file2 #tag1
git diff #当前与staging area比较
repository比较
newbranch的比较
git diff HEAD #当前与
git diff new-brach #当前与
git diff –stat
1.9 git tag
git tag v1 ebff #为
git tag
commit ebff810c462234433434323334343设置标记v1
版本1 ebff #tag可以为中文
版本1 #删除标记版本1
git tag -d
1.10 git log
git log #列出所有
git log –all
git log -p #列出log
log及修改的内容
filename的log及修改内容列出来
git log -p filename #将
git log –name-only #列出哪些文件被修改
git log –stat –summary #列出各个版本间的改动及行数
git log filename #这个文件的所有
git log directory #这个目录的所有
git log -S'FUNC()‘ #列出由
git log –no-merges #不要列出log
log
FUNC()这个字符串的log
log
merge的log
git log –since="2 weeks ago" #列出最后两周的
git log –pretty=oneline
git log –pretty=short
1.11 git show
git show ebff #显示
git show v1 #显示commit ebff810xxxxxxxxxxx的内容
tag:v1的文件修改内容
tag v1的修改内容
git show v1: #显示
git show HEAD #当前版本的修改文件
git show HEAD^ #前一版本所有修改的文件
git show HEAD~4 #前4版本的修改文件
1.12 git reset
git reset –hard HEAD^ #还原到前一版本
git reset –soft HEAD~3
1.13 git grep
git grep "hello" v1 #查找
git grep "hello"
tag:v1中是否由“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 / #增加远程repository的branch
repository
git remote show #列出现在由多少
git remote rm new-branch #删除服务器上的新分支
git remote update #更新所有repository branch
1.20 git fetch
git fetch origin
1.21 git push
git push origin:heads/xxx-branch
2 repo command
2.1 repo init
repo init -u URL #在当前目录安装repo,该命令创建一个.repo文件夹,文件夹中包含一些git仓库,这些仓库包含着repo源代码何manifest文件。
++ -u:制定一个获取manifest仓库的URL。 ++ -m:选择一个仓库中的manifest,默认是 ++ -b:制定一个版本,也就是一个特别的manifet-branch
2.2 repo sync
repo sync [PROJECTLIST] #下载新的改变和更新当前目录下的工作文件,该命令相当与git remote update;git rebase origin/BRANCH (BRANCH本地分支)
++ -d:将制定工程切换到特定的manifest版本 ++ -s:同步当前工程到一个由manifet-server元素指定的可编译的版本 ++ -f:继续同步其他工程,即使有错误发生
2.3 repo upload
repo upload [PROJECTLIST] #上传修改的代码
2.4 repo diff
repo diff [PROJECTLIST]
2.5 repo download
repo download target revision #下载特定的版本到本地
2.6 repo forall
repo forall -c command #对每一个项目执行command
2.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的project
2.10 repo status
repo status #显示每个仓库的状态
3 创建本地repo服务器
mkdir repositories
cd repositories
git init –bare
git init –bare
git init –bare
cd -
mkdir myrepo
cd myrepo
git clone /path/to/
cd manifest
create a file with following content:
review="" /> git add –all git commit -a -m "add " git push –all cd .. git clone /path/to/ cd project1 echo "hello project1" > git add -all git commit -a -m “add in project1" git push -all cd .. git clone /path/to/ cd project2 echo "hello project2" > git add -all git commit -a -m "add in project2" git push -all cd ../.. mkdir myproject cd myproject repo init -u /path/to/ repo sync repo log Date: 2012-05-05 六 Author: Yanqing Li Org version 7.8.11 with Emacs version 24 Validate XHTML 1.0
版权声明:本文标题:git常用命令解释 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://roclinux.cn/p/1708269162a518192.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论