repo git基础命令操作

repo git 基础命令操作(持续更新)

git


初始化git

  • git init
  • git push
  • git pull

  • git rm file(从缓存区和工作区删除)

  • git rm file –cached(不从工作区删除)

分支操作

  • git branch 分支名(创建分支)
  • git checkout 分支名(切换分支)
  • git checkout -b (branchname) (创建并切换)
  • git branch(列出分支)
  • git branch -d 分支名(删除分支)
  • git merge newtest(将newtext分支合并到当前分支上)

当你切换分支的时候,Git 会用该分支的最后提交的快照替换你的工作目录的内容, 所以多个分支不需要多个目录

编辑提交

  • git add
  • git commit -m “”
  • git commit -a(add and commit)

版本回退

  • git checkout – file(将改动还原)
  • git reset HEAD file(将add还原删除add动作(将缓存中的移除))

查看信息

  • git blame file(查看文件每一行的改动)
  • git log
  • git log –pretty=oneline(查看提交信息)
  • git config –list (配置信息罗列)
  • 尚未缓存的改动:git diff
  • 查看已缓存的改动: git diff –cached
  • 查看已缓存的与未缓存的所有改动:git diff HEAD
  • 显示摘要而非整个 diff:git diff –stat

高级

  • tag

repo(管理git)

1.还原改动到具体时间点以前

repo forall -c 'commitID=`git log --before "2018-01-05 12:00" -1 --pretty=format:"%H"`; git reset --hard $commitID'
  1. 提交所有仓库的改动

    • 拉代码

      • export PATH=”~/bin:$PATH”

      • repo init -u ssh://172.20.5.245/mtk/manifest -b ANDROID_O_5658 (拉代码)

      • repo sync
    • 更新代码(也可直接repo sync)

      • repo forall -c git reset –hard
      • repo forall -c git clean -df
      • repo forall -c git pull
    • 提交上传

      • repo forall -c git add .

      • repo forall -c git commit -m “提交”

      • repo upload

    • 分支
      • repo start AndroidTV_N –all(给所有git仓库开分支)
      • repo branch 查看当前分支
      • repo checkout Androidbranch 切换到Androidbranch分支上
      • repo forall -c git status > status-1.txt(将status的重定向到一个文件里面去)
      • find release -name *.h -exec rm {} \;(删除目录中所有 以.h结尾的文件)

3.版本记录追溯

版本记录(按需,一般版本集成人员需要掌握)
为了方便记录版本,用与追溯问题。在每次发布版本时需要制作一个 xml,来记录所有仓库的状态。

①制作 xml:在当前环境下执行 repo manifest -r -o .repo/manifests/151126.xml。其中 xml
名字以当前日期命名方便查看。151126 将记录在工厂菜单作为系统 svn 版本号。该 xml 会
记录所有仓库当前的 commit id.

②提交 xml 到 gerrit:
cd .repo/manifests
git add 151126.xml
git commit -m “log”
git push origin HEAD:refs/for/branch
注意:branch 一定要跟你 repo init -u xxx -b branch 的分支一致,否则你将提交
到别的分支上去了。代码审核人员一定要注意查看。

③导入 xml:
当要切换到某个版本环境时,如果本地已经有代码了。
直接:
repo init -m 151126.xml
repo sync

如果还没下载过代码,可以在初始化时 repo init -u U r l b Branch -m 151126.xml

猜你喜欢

转载自blog.csdn.net/xct841990555/article/details/80435706