新建本地分支
git checkout -b myRelease origin/Release
设置分支对应的远程分支
git branch --set-upstream-to develop-20170831 origin/master
查看分支信息,-vv包括对应远程分支信息
git branch -vv 或-v
创建远程分支
git checkout -b branchName
git push origin branchName:branchName
忽略文件的修改和重新释放
git update-index --assume-unchanged /path/file //忽略修改
git update-index --no-assume-unchanged /path/file //恢复跟踪
切分支前储藏当前分支的所有内容
git stash save -u
切回分支恢复之前储藏的内容
git stash pop
恢复本地修改
git reflog 查看本地分支更改日志
git reset --hard 06e2af77c7 回退到对应版本号
区别:
git log是显示当前的HEAD和它的祖先的,递归是沿着当前指针的父亲,父亲的父亲,…,这样的原则。
git reflog根本不遍历HEAD的祖先。它是HEAD所指向的一个顺序的提交列表
本地创建远程分支并push
1.git checkout -b test
2.git push origin test:test
3.git push --set-upstream origin test
查看日志(美化版)
git log --graph --pretty=oneline
git fetch
git pull = git fetch + git merge
git rebase
1.用法之【合并无意义的提交】
git rebase -i HEAD~4 #合并最近的 4 次提交纪录
进入gnu nano或vi编辑模式
第一列为操作指令,第二列为commit号,第三列为commit信息。
有以下提示命令:
pick 19a4c63 Modified two commits
pick 85a4c42 Modified two commits
# Commands:
# p, pick = use commit
# r, reword = use commit, but edit the commit message
# e, edit = use commit, but stop for amending
# s, squash = use commit, but meld into previous commit
# f, fixup = like "squash", but discard this commit's log message
# x, exec = run command (the rest of the line) using shell
# d, drop = remove commit
把最后一个pick改为squash,按ctr+x,再按Y退出编辑模式, 然后会让你填两次提交的注释,继续 ctr+x ,然后按 Y 退出即可。
2.合并分支
git rebase origin/test
#用在从上游分支获取最新commit信息,并有机的将当前分支和上游分支进行合并
git log配置别名
git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"
修改远程分支命名
git branch -m old_branch new_branch 修改本地分支
git push origin :old_branch 删除远程分支
git push --set-upstream origin new_branch