git&repo
git常用指令
用户名/邮箱:
1 2 3 4 5 6 7 8
| 设置用户名: git config --global user.name your_name 设置邮箱: git config --global user.email your_email_address 查看用户名: git config user.name 查看邮箱: git config user.email
|
远端管理
1 2 3 4 5 6 7 8 9 10 11
| 增加远端: git remote add remote_name url
建立本地分支与远端分支的跟踪关系: git branch --set-upstream-to=remote_name/remote_branch_name local_branch_name
删除远端: git remote remove remote_name
清理无效的远程追踪分支: git remote prune remote_name
|
分支管理:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| 查看分支: git branch -vva (显示所有本地及远端分支并展示两者之间的跟踪关系)
分支重命名 git branch -m old_branch_name new_branch_name
创建本地分支: git checkout -b new_branch_name 在本地创建基于远端的分支(不会建立跟踪关系): git fetch remote_name remote_branch_name:local_branch_name 推送本地分支到远端(创建远端分支)并建立跟踪关系: git push -u remote_name local_branch_name:remote_branch_name
切换分支: git checkout branch_name
删除本地分支: git branch -d branch_name 删除远端分支: git push remote_name :remote_branch_name (local_branch_name为空)
|
历史管理:
1 2 3 4
| 显示每个提交所在的分支及其分化衍合情况: git log --graph 回退: git reset --hard commit id
|
submodule管理:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| clone submodule到当前仓库:(如果clone的是无push权限的仓库,先fork) git submodule add url local_path
提交对submodule的修改: 进入submodule路径push,退回本地仓库路径push
删除submodule: git submodule deinit submodule_name git rm --cached submodule_name 删除submodule目录 删除.gitmodules .git/config .git/module/* 中submodule相关内容
clone含有submodule的仓库: git clone url git submodule init && git submodule update 或者 git clone url --recursive
|
patch管理:
1 2 3 4 5 6 7 8 9
| 生成patch: git format-patch start_commit_id..end_commit_id 使用patch: git am patch_path/* 解决冲突: step1:git apply --reject patch_name step2:根据.rej文件手动修改源码 step3:git add . step4:git am --continue
|
repo指令
分支管理:
1 2 3 4
| 查看:repo branch 创建:repo start branch_name --all(对所有工程) 切换:repo checkout branch_name 删除:repo abandon branch_name
|
对所有工程执行脚本
repo forall -c 'git checkout branch_name'
github
参考教程 https://www.liaoxuefeng.com/wiki/896043488029600/900937935629664
git国内下载站 https://github.com/waylau/git-for-win
生成SSH-KEY: ssh-keygen -C “email”