Git clone只能clone远程库的master分支,无法clone所有分支
$ git clone [email protected]:special-lily/dingding.git
Cloning into 'dingding'...
remote: Counting objects: 52, done.
remote: Compressing objects: 100% (47/47), done.
remote: Total 52 (delta 4), reused 52 (delta 4), pack-reused 0
Receiving objects: 100% (52/52), 1.20 MiB | 308.00 KiB/s, done.
Resolving deltas: 100% (4/4), done.
指定用户名密码进行clone:git clone https://用户名:密码@github.com/special-lily/dingding.git
$ git clone https://username:[email protected]
Cloning into 'dingding'...
remote: Counting objects: 74, done.
remote: Compressing objects: 100% (16/16), done.
remote: Total 74 (delta 10), reused 15 (delta 6), pack-reused 52
Unpacking objects: 100% (74/74), done.
克隆下来之后 打开项目文件夹
$ cd dingding
查看所有分支 前面带*号的代表你当前工作目录所处的分支
$ git branch -a
* master
remotes/origin/HEAD -> origin/master
remotes/origin/gh-pages
remotes/origin/master
查看各个分支当前所指的对象。 提供这一功能的参数是 --decorate。(不明)
$ git log --oneline --decorate
3611f31 (HEAD -> master, origin/master, origin/HEAD) Initial commit
创建本地分支,新分支创建后不会自动切换为当前分支
$ git branch dev
查看所有分支, 上条命令创建的是本地分支
$ git branch -a
dev
* master
remotes/origin/HEAD -> origin/master
remotes/origin/gh-pages
remotes/origin/master
查看远程分支
$ git branch -r
origin/HEAD -> origin/master
origin/dev
origin/gh-pages
origin/master
查看本地分支 前面带*号的代表你当前工作目录所处的分支
$ git branch
dev
* master
只把部分修改的文件添加到暂存区
$ git add index-dev.html
删除本地dev分支
$ git branch -d dev
error: Cannot delete branch 'dev' checked out at 'E:/dingding-lijian/dingding'
删除失败 因为现在正在处于检出状态, 切换分支到master
$ git checkout master
Switched to branch 'master'
Your branch is up-to-date with 'origin/master'.
再次执行删除分支
$ git branch -d dev
error: The branch 'dev' is not fully merged.
If you are sure you want to delete it, run 'git branch -D dev'.
删除失败 因为dev分支没有被merge,如果仍要删除就使用git branch -D dev
删除本地分支
$ git branch -D dev
Deleted branch dev (was 7a25f30).
把本地分支代码更新到远程分支,git push origin 本地分支名:远程分支名
$ git push origin dev:dev
Total 0 (delta 0), reused 0 (delta 0)
To github.com:special-lily/dingding.git
3611f31..7a25f30 dev -> dev
创建远程分支:把本地分支推到远程
$ git push origin dev
Total 0 (delta 0), reused 0 (delta 0)
To github.com:special-lily/dingding.git
* [new branch] dev -> dev
远程分支名不存在 ,就会自动创建一个新的远程分支
$ git push origin dev:dev2
Counting objects: 3, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 441 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To github.com:special-lily/dingding.git
* [new branch] dev -> dev2
删除远程分支
$ git branch -r -d origin/dev2
Deleted remote-tracking branch origin/dev2 (was 7a25f30).
如果本地分支名为空则删除:右侧的远程分支
$ git push origin :dev
To github.com:special-lily/dingding.git
- [deleted] dev
从远程分支创建本地新分支 并检出:在远程的gh-pages分支上创建本地分支名为dev-gh分支,并切换到本地的dev-gh分支
$ git checkout -b dev-gh origin/gh-pages
Branch dev-gh set up to track remote branch gh-pages from origin.
Switched to a new branch 'dev-gh'
在当前本地分支上 创建新分支
$ git checkout -b dev-gh2
Switched to a new branch 'dev-gh2'
用gitk来查看commit的结果,你会看到它有两个父分支:一个指向当前的分支,另外一个指向刚才合并进来的分支
$ gitk
拉取远程分支最新代码
$ git pull origin gh-pages:dev-gh2
Already up-to-date.
也可以直接执行 git pull
$ git pull
Warning: Permanently added the RSA host key for IP address '192.30.253.113' to the list of known hosts.
From github.com:special-lily/dingding
* [new branch] dev2 -> origin/dev2
Auto-merging index.html
CONFLICT (content): Merge conflict in index.html
Auto-merging css/index.css
CONFLICT (content): Merge conflict in css/index.css
Automatic merge failed; fix conflicts and then commit the result.
自行解决冲突 并 git add , git commit
把dev分支与当前分之合并
$ git merge dev
Auto-merging index.html
CONFLICT (content): Merge conflict in index.html
Automatic merge failed; fix conflicts and then commit the result.
查看某个文件中部分代码由谁修改过
$ git blame css/index.css
fc6439f5 (Datura900607 2016-07-26 21:03:05 +0800 194) width: 100%;
fc6439f5 (Datura900607 2016-07-26 21:03:05 +0800 195) position:absolute;
fc6439f5 (Datura900607 2016-07-26 21:03:05 +0800 196) left: 0;top: 800px;
fc6439f5 (Datura900607 2016-07-26 21:03:05 +0800 197) text-align: center;
0c50d7bc (special-lily 2017-07-20 17:31:01 +0800 198) color: #e4b9c0;
0c50d7bc (special-lily 2017-07-20 17:31:01 +0800 199) background-color: #ffffff;
fc6439f5 (Datura900607 2016-07-26 21:03:05 +0800 200) }
(END)
分区块暂存
$ git add -p index.html
diff --git a/index.html b/index.html
index 9d084ea..5f83bea 100644
--- a/index.html
+++ b/index.html
@@ -109,10 +109,11 @@
+ éé??o????éèo??é??è′1?§??¨????13?°1
+ éé??o????éèo??é??è′1?§??¨????13?°2
+ éé??o????éèo??é??è′1?§??¨????13?°3
éé??o????éèo??é??è′1?§??¨????13?°
?¨?o??§??¨????£??éé???o????a?·¥???1?? (??é¤ )
- éé??o????éèo??é??è′1?§??¨????13?°
- ?¨?o??§??¨????£??éé???o????a?·¥???1?? (?¨dev ??ˉ??-?·???????1)