创建分支

git checkout -b new_branch

基于远程分支创建分支

git checkout -b new_dev origin/develop

等效于创建并切换到新分支

git branch new_branch && git checkout new_branch

合并两个不同的git库

假如有两个git库,第二个是从第一个folk过去的,那边有修改的commit需要同步到本地的git里边,首先进入git目录

# 添加folk库为新的远程源
git remote add folk git-url
# 同步所有代码分支到本地
git fetch
# 挑选提交
git cherry-pick commmit-id
# 分支合并
git merge fork/bugfix

推送到远程

git push origin new_branch:remote_branch

删除远程分支

git push origin --delete dev_nanyao

建立映射关系

将dev_nanyao分支映射到远程develop

git branch --set-upstream-to origin/develop dev_nanyao
#或者
git branch --set-upstream develop origin/develop

commit 模板

git config --global commit.template /home/lany/.config/git/template

指定编辑器

git config --global core.editor vim

代理

查看git代理

git config --global -l

设置git代理

命令行设置(临时)
//设置全局代理
//http
git config --global http.proxy http://127.0.0.1:1080
//https
git config --global https.proxy https://127.0.0.1:1080
//使用socks5代理的 例如ss,ssr 1080是windows下ss的默认代理端口,mac下不同,或者有自定义的,根据自己的改
git config --global http.proxy socks5://127.0.0.1:1080
git config --global https.proxy socks5://127.0.0.1:1080
//只对github.com使用代理,其他仓库不走代理
git config --global http.https://github.com.proxy socks5://127.0.0.1:1080
git config --global https.https://github.com.proxy socks5://127.0.0.1:1080

修改~/.gitconfig配置文件(永久性)

[http]
    proxy = socks5://127.0.0.1:1080
[https]
    proxy = socks5://127.0.0.1:1080'

取消git代理

取消仅对https://github.com设置的代理
git config --global --unset http.https://github.com.proxy
git config --global --unset https.https://github.com.proxy
​
1.3.2 取消git对所有网站的代理
git config --global --unset http.proxy
git config --global --unset https.proxy

修改提交用户和邮箱

// 全局修改
git config --global user.name "silinchen"
git config --global user.email "silinccc@gmail.com"
// 针对某个仓库修改
git config user.name "silinchen"
git config user.email "silinccc@gmail.com"

修改已commit用户

修改最近提交的

git commit --amend --author="orchingly orchingly@gmail.com" --no-edit

修改倒数第二条提交

git rebase -i HEAD~2
//将需要修改的记录标记为e
//保存退出后执行,修改邮箱名字,--no-edit不编辑comment
//多条记录,多次执行
git commit --amend --author="orchingly <orchingly@gmail.com>" --no-edit

修改首次提交

git rebase -i --root

本地仓库绑定github

首次添加
git  remote add origin git@github.com:orchingly/wvp-android.git
已有origin 修改
git remote set-url origin git@github.com:orchingly/wvp-android.git

git 代码迁移保留commit记录

先克隆原仓库

git clone xxx.git

checkout 本地分支

git checkout -b local_branch

删除和原git库的关系

git remote remove origin

建立与新git库的关系

git remote add origin git@xxx.xxx.xxx.xxx:xxx_new.git

将本地分支提交到远程分支并建立映射关系

git push --set-upstream origin local_branch:master

至此,本地分支带提交记录全部添加到远程master分支

春风花气馥,秋月寒江湛