git命令备注

git config -l
查看git仓库url、分支信息
git diff > xx.patch
生成补丁
patch -p1 < xx.patch
打补丁

git add 
git commit
git commit –amend
git push 8994la13 master:refs/for/QB8994/master	

git commit是提交到本地代码仓库,git push是提交到远程代码仓库。
8994la13 远程GIT仓库别名,代表url和git仓库名 git remote -v 查看
master 本地分支
QB8994/master 远程git仓库分支

git status 
git log	--stat
git log --author=提交人姓名拼音		查看指定人的代码提交
git show commitid  查看某次commit修改内容
git diff	查看尚未暂存的更新
git show	
git log -p <filename>查看某个文件的修改历史
git pull 把远程git仓库某一分支拉到本地并合并   !!git pull慎用会生成merge节点导致无法push
git reset HEAD^	  把最近一次commit撤出暂存区
git reset HEAD^ --soft  把最近一次commit撤出本地仓库
git branch -d | -D branchname 删除branchname分支
git checkout -b 本地分支  远程仓库名/远程分支	创建切换一个跟踪远程仓库分支的本地分支
例如:git checkout -b debug mtk6755/MTK6755/master

git pull 更新远程仓库并自动合并 !不安全
git fetch 更新远程仓库,不自动合并

git blame:查看文件每一行的提交信息,包括日志、作者等
-L 参数指定开始和结束行。例如git blame -L 160,+10 文件名
  • git pull 时自动生成merge 节点导致无法push?
    把自己的本地分支删除,重新切换一个本地分支

  • git pull文件冲突

git stash	stash@{0}就是刚才保存的标记
git pull	
git stash pop stash@{0}  还原暂存的内容
手动解决冲突后再递交
  • repo命令
repo init -u url -m xxx.xml	repo 初始化 如果不使用-b指定分支,就使用.repo/manifest文件里默认的分支
repo sync
repo sync project1 project2	下载某个git仓库
repo start 本地分支名  --all	把所有的项目工程切换到某一个分支
  • hooks脚步下载
    gerrit通过change_id管理活动走读,hooks脚步就是git commit时生成change_id的。
    repo sync后,.git/hooks目录下都有commit-msg脚本。
    如果没有的话,可以把.repo/repo/hooks/commit-msg文件拷贝到.git/hooks目录下。

  • 下载代码流程

repo init -u
repo sync
repo start 本地分支名  --all(切换所有仓库到指定分支)
  • 更新远程仓库代码到本地的方法2种
git pull  操作默认会执行git merge操作,会自动生成新的merge节点。不推荐使用。
git fetch 更新远程仓库到本地,不自动合并
git pull = git fetch + git merge
git pull --rebase = git fetch + git rebase
建议流程:
git fetch
git rebase 远程GIT仓库别名/远程分支
1:单个git仓清除本地所有修改
git checkout . ; git clean -fdx . 
2:清除本地所有仓的修改
repo forall  –c  ‘git checkout . ; git clean -fdx .’

git checkout . (.表示当前目录  清除所有跟踪的文件 不包括新增的文件)
git clean -fdx . (清除本地所有新增文件,不包括跟踪文件)

2:git仓下载一个远程分支到本地
git fetch origin remote_branchname 
下载git仓所有远程分支到本地
git pull  

3:更新代码
git pull origin remote_branchname   git命令更新git仓
repo  sync  -c  -j8
repo sync  -c   .   进入git仓路径,更新单个git仓
repo sync  -c git仓路径				更新单个git仓
-c 只更新.repo/manifest.xml中revision定义的分支代码,不添加 -c 就更新git仓的全部分支

4:代码提交
git push origin local_branchname:refs/for/remote_branchname
原文地址:https://www.cnblogs.com/bobfly1984/p/14111583.html