git从分支克隆、通过fetch等更新本地仓库、本地提交查看版本等
从分支克隆
1.不指定分支克隆
1
|
git clone https://github.com/vuejs/vue.git
|
2.指定分支克隆
1
|
git clone -b dev https://github.com/vuejs/vue.git
|
通过fetch更新本地仓库
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
//方法一 $ git fetch origin master //从远程的origin仓库的master分支下载代码到本地的origin master
$ git log -p master.. origin/master//比较本地的仓库和远程参考的区别
$ git merge origin/master//把远程下载下来的代码合并到本地仓库,远程的和本地的合并
//方法二 $ git fetch origin master:temp //从远程的origin仓库的master分支下载到本地并新建一个分支temp
$ git diff temp//比较master分支和temp分支的不同
$ git merge temp//合并temp分支到master分支
$ git branch -d temp//删除temp
|
git比较本地仓库和远程仓库的差异
1.更新本地的远程分支
2.本地与远程的差集 :(显示远程有而本地没有的commit信息)
1
|
git log master..origin/master
|
3.统计文件的改动
1 2
|
# git diff <local branch> <remote>/<remote branch> git diff --stat master origin/master
|
git本地仓库初始化及提交
从远程仓库抓取更新到本地。其中第一次需要对本地做git init
,然后进.git目录
第一次需要将本地库提交到github上。
1 2 3 4 5 6 7 8 9 10 11
|
git push -u origin master
git remote -v
git pull origin master
git fetch origin master
git log -p master.. origin/master
git merge origin/master
|
git提交到远端
1 2 3 4 5 6 7 8
|
git status
git add .
git commit -m "tag update"
git push -u origin master
|
git分支
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
|
$ git branch
$ git branch -r
$ git branch -a
$ git branch [branch-name]
$ git checkout -b [branch]
$ git branch [branch] [commit]
$ git branch --track [branch] [remote-branch]
$ git checkout [branch-name]
$ git checkout -
$ git branch --set-upstream [branch] [remote-branch]
$ git merge [branch]
$ git cherry-pick [commit]
$ git branch -d [branch-name]
$ git push origin --delete [branch-name] $ git branch -dr [remote/branch]
|
查看信息
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
|
$ git status
$ git log
$ git log --stat
$ git log -S [keyword]
$ git log [tag] HEAD --pretty=format:%s
$ git log [tag] HEAD --grep feature
$ git log --follow [file] $ git whatchanged [file]
$ git log -p [file]
$ git log -5 --pretty --oneline
$ git shortlog -sn
$ git blame [file]
$ git diff
$ git diff --cached [file]
$ git diff HEAD
$ git diff [first-branch]...[second-branch]
$ git diff --shortstat "@{0 day ago}"
$ git show [commit]
$ git show --name-only [commit]
$ git show [commit]:[filename]
$ git reflog
|
远程同步
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
$ git fetch [remote]
$ git remote -v
$ git remote show [remote]
$ git remote add [shortname] [url]
$ git pull [remote] [branch]
$ git push [remote] [branch]
$ git push [remote] --force
$ git push [remote] --all
|
增加删除文件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
$ git add [file1] [file2] ...
$ git add [dir]
$ git add .
$ git add -p
$ git rm [file1] [file2] ...
$ git rm --cached [file]
$ git mv [file-original] [file-renamed]
|
部分笔记参考📒
常用Git命令清单:http://www.ruanyifeng.com/blog/2015/12/git-cheat-sheet.html
优秀的笔记📒
中文版权威教程Git Pro:https://gitee.com/progit/
简明使用指导:https://www.liaoxuefeng.com/wiki/896043488029600
好玩的git教程及游戏😀
git简易指南:https://www.bootcss.com/p/git-guide/
git游戏:https://learngitbranching.js.org/?demo
近期评论