@JunQiu
2018-11-01T13:15:14.000000Z
字数 1192
阅读 2381
git summary_2018/11
// 创建分支并切换$ git branch dev-#1$ git checkout dev-#1// 等价于$ git checkout -b dev-#1
// 本地分支(-r 远程分支,-a所有分支)git branch// 切换到远端某个分支git branch -rgit checkout 远端分支 -f(强制覆盖当前分支未提交的修改)
// 当前有master分支和dev-1分支,处于master分支,将dev-1分支合并到master分支:$ git merge dev-1Auto-merging test.jsCONFLICT (content): Merge conflict in test.jsAutomatic merge failed; fix conflicts and then commit the result.// 如果没有冲突将会合并,但由于在test.js文件存在冲突。因此,需要手动解决冲突:// 可以用git status查看冲突的文件$ git statusOn branch masterYou have unmerged paths.(fix conflicts and run "git commit")(use "git merge --abort" to abort the merge)Changes to be committed:new file: .idea/vcs.xmlmodified: .idea/workspace.xmlUnmerged paths:(use "git add <file>..." to mark resolution)both modified: test.js我们可以在文件中看到,进行手动合并:<<<<<<< HEADconsole.log('git test 1')=======console.log('git test')>>>>>>> dev-1// 可以两者选择一个,也可以均保留/删除:console.log('git test 1')console.log('git test')// 标记冲突解决并提交:git add .git commit
// 回退到上一个版本,上上一个HEAD^^,往上100:HEAD~100git reset --hard HEAD^/commit idTips:git reflog可以查看历史命令
// 清空暂存区,放回工作区,仅覆盖工作区在暂存区存在的对应文件git reset HEAD
// 清空工作区的修改git checkout -- <file>..." to discard changes in working directory
