git 是用于解决多人协作和软件版本迭代的好工具,掌握git的使用是计算技术人员的必备技能。后续我们在开发代码时,会大量使用到git,所以掌握必要的git编辑能力很重要,可以避免版本冲突,便于版本管理和备份。
推荐的git学习资源
基本的命令
请务必掌握以下命令的使用:
1 2 3 4 5 6 7 8 9
| git clone <remote-url> git fetch <remote name> <remote branch name> git merge FETCH_HEAD <local branch name> git add git commit -m "评论" git push <remote name> <local branch name> git branch -a git branch <new branch name> git checkout <new branch name>
|
本部分掌握后,再考虑掌握进阶的使用。
其他常见命令
1 2 3 4 5 6 7 8
| git log git log -1 git show HEAD git show HEAD^ git merge origin/master touch ls vi
|
Git分支操作
1 2 3 4 5 6 7 8 9 10 11 12 13
| git checkout -b <branchname> git checkout <branchname> git branch git branch <new branch name> git branch -r git branch -a git merge <branchname> git branch -d <branchname> git branch -D <branchname> git branch --no-merged git branch -m master master_copy git branch -vv git fetch origin --prune
|
Git解决冲突
适用于两个分支或者多个分支都发生变化时,合并两个分支时会发生错误 Merge
进行合并选择
Git远程连接
1 2 3 4 5 6 7 8 9
| git init git remote add origin <URL地址> git remote git push origin <本地分支> git push [-f] [--set-upstream] origin <本地分支>:<远程分支> git push
git fetch <remote name> <remote branch name> git pull <remote name> <remote branch name>
|