Wednesday, November 22, 2017

Git

版本回退:
git log: 查看提交历史
git log --graph: 查看分支合并图
git reflog: 查看命令历史
git reset --hard commit_id: 回退到了某个版本
git reset --hard HEAD^: 回退到上一个版本
git reset --hard HEAD~10: 回退到之前第十个版本

撤销修改:
git checkout -- file: 可以丢弃工作区的修改(或删除操作), 让file这个文件回到最近一次git commit或git add时的状态
git reset HEAD file: 可以把暂存区的修改撤销掉,重新放回工作区

分支管理:
git merge --no-ff -m <commit-info> <branch-name>: 强制禁用Fast forward模式,Git就会在merge时生成一个新的commit,从分支历史上就可以看出分支信息
git stash: 把当前工作现场“储存”起来
git stash apply: 恢复储存的内容,但是恢复后,stash内容并不删除
git stash drop: 删除stash的内容
git stash pop: 恢复的同时把stash内容也删了
git stash apply stash@{0}: 如果有多次stash的话,选择恢复某个stash内容

配置别名:
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 checkout mainline
git pull
git checkout dev
git rebase mainline
(resolve conflicts + commit)
git checkout mainline
git merge dev
git push origin mainline












No comments:

Post a Comment