Git指令
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
学习网站
https://learngitbranching.js.org/
https://blog.youkuaiyun.com/web_csdn_share/article/details/79243308
https://www.cnblogs.com/qianqiannian/p/6008140.html
https://www.cnblogs.com/qianqiannian/p/6005628.html
https://www.cnblogs.com/qianqiannian/p/6010219.html
不需要git验证
git config --global http.sslVerify false
初始化
git init
查看本地所关联的远程仓库
git remote
git remote -v
git remote --help
git remote get-url --all
关联
git remote add origin https://xxx
取消关联远程仓库
git remote remove xxx
修改关联远程仓库
1/git remote set-url origin <newurl>
git remote remove <name>
2/git remote add <name> <url>
3/直接修改项目目录下的 .git 目录中的 config 配置文件
提交
git add .
git commit -m"修改内容"
git commit -a -m 不经过暂存区,不推荐
对某个记录继续添加修改
git reset --hard commit-id 先找到对应记录,回退版本
git add
git commit --amend 不产生新的记录
git push
提交代码1
git fetch
git rebase origin/master
git merge origin/master
git push 当前分支只有一个远程分支
提交代码2
git pull --rebase
git push 当前分支只有一个远程分支
git push origin --all 将本地的所有分支都推送到远程主机
git push -u origin --all
git push origin 当前分支推送到origin主机的对应分支
git push origin master -f 强制提交
git push -u origin master 使用 -u 参数指定一个默认主机,后面直接使用 git push
git push origin :master 省略本地分支,就是删除远程分支
git push origin --delete master 远程删除分支
git push <远程主机名> <本地分支名> <远程分支名>
提交同名分支
git push origin master
不同名字分支同步
git push origin local_branch:remote_branch
远程没有分支会新建并同步
git push origin local_branch:remote_branch
refs/for 的意义在于我们提交代码到服务器之后是需要经过code review 之后才能进行merge的,而refs/heads 不需要
关于Tag
git tag 0.0.1
git tag 0.0.2 commit_id 从某个记录打Tag
推送tag
git push --tags
git push origin --tags
git push -u origin --tags
删除tag
git tag -d 0.0.1
git push origin:0.0.1
下载、更新、拉取
远程仓库
git fetch只是下载 origin/master
git pull = fetch + merge
git pull --rebase == fetch + rebase
变基 rebase
rebase对任何已经提交到公共仓库中的commit不能进行修改
git rebase name
git rebase master bugFix
git rebase --continue
合并 merge
git merge name
默认下载所有分支
git fetch
git fetch origin :local_branch 新建本地分支
git fetch <远程主机名> <远程分支名> <本地分支名>
本地不存在的提交,放到本地的 o/foo 上
git fetch origin master
不同名字分支同步
git fetch origin remote_branch:local_branch
//本地没有分支会新建并同步
git fetch origin remote_branch:local_branch
克隆、关联新分支
下载分支
git clone -b name url
git clone -b name v2.8.1 url
新建分支关联远程仓库
git checkout -b new_branch origin/master
关联远程仓库到本地分支
git branch -u origin/master new_branch
git clone -b new_branch http://
git clone http://xxxx.git --depth=1 只克隆最近一次commit
git branch -r 查看远程分支名
git branch -a 查看所有分支名
新建分支
git branch name
git checkout -b name
git branch -f master HEAD~3 //强制修改分支位置
git branch -d name //删除分支
git branch -r 查看远程分支名
git branch -a 查看所有分支名
分离HEAD
git checkout <HEAD> 哈希值前面几位就可
git checkout HEAD^ 使用 ^ 向上移动 1 个提交记录
git checkout HEAD~3 使用 ~<num> 向上移动多个提交记录
git checkout HEAD~^2~2 链式操作
git checkout master^ 相当于“master 的父节点”
git checkout master^^ 是 master 的第二个父节点
git checkout master^2 默认第一个父类 ,2表示第二个父类
日志
git log
git log --oneline -3 查看最近3次提交
git reflog 回退错误时使用
状态
git status
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
回退、撤销
没有提交远程的更改
git reset (–mixed) HEAD~1
回退一个版本,且会将暂存区的内容和本地已提交的内容全部恢复到未暂存的状态,不影响原来本地文件(未提交的也不受影响)
git reset –soft HEAD~1
回退一个版本,不清空暂存区,将已提交的内容恢复到暂存区,不影响原来本地的文件(未提交的也不受影响)
git reset –hard HEAD~1
回退一个版本,清空暂存区,将已提交的内容的版本恢复到本地,本地的文件也将被恢复的版本替换
git reset --hard xxx 本地文件和commit信息都回退了
git reset --sort xxx
git reset --soft HEAD~1 本地文件还在,只回退commit
git reset --hard xxx 退到/进到 指定commit的sha码
git reset --hard HEAD^ 回退到上个版本
git reset --hard HEAD~n 回退到前n次提交之前
远程撤销,已经提交远程的更改
git revert HEAD
git push origin master -f 强制提交
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
暂存
git stash
git stash save "xxx"
git stash pop 缓存堆栈中的第一个stash删除,并修改到当前目录下
git stash apply 缓存堆栈中的stash多次应用到工作目录中,但并不删除stash拷贝
查看现有stash
git stash list
git stash apply stash@{0} 可以指定哪个stash,默认是0
移除stash
git stash list
git stash drop stash@{0}
删除所有缓存的stash
git stash clear
暂存提取出来,开辟新的分支
git stash branch testchanges
学习网站
https://www.cnblogs.com/yf2196717/p/11473738.html
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
查看git配置
vim ~/.gitconfig
git config --global user.name "name"
git config --global user.email "xxx@qq.com"
查看系统config
git config --system --list
查看当前用户(global)配置
git config --global --list
查看当前仓库配置信息
git config --local --list
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
SourceTree
git config credential.helper store
保存密码
git config credential.helper store
加密 ssh
https://www.jianshu.com/p/dc484632c547
https://www.cnblogs.com/youqc/p/9260428.html
ssh-keygen -t rsa
cd ~/.ssh
ssh-keygen -t rsa -C "wangpengfei@purang.com"
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
.bash_profile
source ~/.bash_mygit
快捷键配置
alias ga="git add"
alias gb="git branch"
alias gc="git commit"
alias gd="git diff"
alias gf="git fetch"
alias gk="gitk --all"
alias gl="git log"
alias gla="git log --oneline --graph --decorate --all"
alias gp="git push"
alias gr="git rebase"
alias gs="git status"
alias gsu="git submodule update"
alias gsa="git config credential.helper store"
Xcode设置Git
*~
.DS_Store
*.patch
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
高级技能
打补丁
git patch指令
git format-patch HEAD^ 生成最近的1次commit的patch
git format-patch HEAD^^^ 生成最近的3次commit的patch
git format-patch <r1>..<r2> 生成两个commit间的修改的patch(包含两个commit. <r1>和<r2>都是具体的commit号)
git format-patch -1 <r1> 生成单个commit的patch
git format-patch <r1> 生成某commit以来的修改patch(不包含该commit)
git format-patch --root <r1> 生成从根到r1提交的所有patch
git apply --status 0001xxxx.patch 查看patch的情况
git apply --check 0001xxxx.patch
检查patch是否能够打上,如果没有任何输出,则说明无冲突,可以打上
(注:git apply是另外一种打patch的命令,其与git am的区别是,git apply并不会将commit message等打上去,
打完patch后需要重新git add和git commit,而git am会直接将patch的所有信息打上去,
而且不用重新git add和git commit,author也是patch的author而不是打patch的人)
git am指令
git am 0001xxxx.patch
将名字为0001xxxx.patch的patch打上
git am --signoff 0001xxxx.patch
添加-s或者--signoff,还可以把自己的名字添加为signed off by信息,
作用是注明打patch的人是谁,因为有时打patch的人并不是patch的作者
git am ~/patch-set/*.patch
将路径~/patch-set/*.patch 按照先后顺序打上
git am --abort
当git am失败时,用以将已经在am过程中打上的patch废弃掉(比如有三个patch,
打到第三个patch时有冲突,那么这条命令会把打上的前两个patch丢弃掉,返回没有打patch的状态)
git am --resolved
当git am失败,解决完冲突后,这条命令会接着打patch
如果打Patch的过程中发生了冲突直接:git am --abort
如果还想打, 有两种解决方案:
方案一(个人推荐):
(1) 根据git am失败的信息,找到发生冲突的具体patch文件,然后用命令git apply --reject <patch_name>,强行打这个patch,发生冲突的部分会保存为.rej文件(例如发生冲突的文件是a.txt,那么运行完这个命令后,发生conflict的部分会保存为a.txt.rej),未发生冲突的部分会成功打上patch
(2) 根据.rej文件,通过编辑该patch文件的方式解决冲突。
(3) 废弃上一条am命令已经打了的patch:git am --abort
(4) 重新打patch:git am ~/patch-set/*.patch
方案二:
(1) 根据git am失败的信息,找到发生冲突的具体patch文件,然后用命令git apply --reject <patch_name>,强行打这个patch,发生冲突的部分会保存为.rej文件(例如发生冲突的文件是a.txt,那么运行完这个命令后,发生conflict的部分会保存为a.txt.rej),未发生冲突的部分会成功打上patch
(2) 根据.rej文件,通过编辑发生冲突的code文件的方式解决冲突。
(3) 将该patch涉及到的所有文件(不仅仅是发生冲突的文件)通过命令git add <file_name>添加到工作区中
(4) 告诉git冲突已经解决,继续打patch: git am --resolved (git am --resolved 和 git am --continue是一样的)
分析:方案一和方案二主要区别是解决冲突的方法不一样。方案一是通过编辑patch文件的方式解决冲突,方案二十通过编辑冲突code文件的方式解决冲突。这两种方案区别比较大:经过实验,核心区别在于,方案二无法验证冲突有没有切实的解决。即使你在方案二的第二步乱改一通,也能“打完”发生冲突的patch(并没有检测修改后的code文件跟patch期望的是否相同)。因此,如果采用方案二,那么再解决code文件冲突后,需要人工去确认修改的正确性。
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
交互式合并几次commit记录
交互式 rebase 指的是使用带参数 --interactive 的 rebase 命令, 简写为 -i
git rebase -i HEAD~4
git rebase -i [startpoint] [endpoint]
注:该区间指定的是一个前开后闭的区间
git rebase -i xxxxx
git rebase -i HEAD~3
复制几次commit记录
git rebase [startpoint] [endpoint] --onto [branchName]
git rebase 90bc0045b^ 5de0da9f2 --onto master
git rebase --onto master banch1 banch2
git rebase --continue/abort/skip
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
整理提交记录
git cherry-pick <提交号>...
git cherry-pick -n 编号
git cherry-pick --continue
git cherry-pick xxx..xxx
git cherry-pick (commitid1..commitid100]
git cherry-pick [<options>] <commit-ish>...
常用options:
--quit 退出当前的chery-pick序列
--continue 继续当前的chery-pick序列
--abort 取消当前的chery-pick序列,恢复当前分支
-n, --no-commit 不自动提交
-e, --edit 编辑提交信息
---------------------
git cherry-pick xxx
git cherry-pick -n xxx
git add .
git cherry-pick --continue
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
2411

被折叠的 条评论
为什么被折叠?



