一、Git本地创建新分支,并推送到远程
1.本地创建分支并切换分支
git checkout -b develop
2. 将develop分支推送到远程
git push origin develop:develop
3. 建立本地至上游(远程)分支的链接,这样代码才能提交到远程
git branch --set-upstream-to=orgin/develop
4.取消对develop分支的跟踪
(需要取消跟踪时才操作)
git branch --unset-upstream develop
5.查看本地分支
$ git branch
* br-2.1.2.2
master
6.查看远程分支
$ git branch -r
origin/HEAD -> origin/master
origin/feature/IOS_visualtrack
origin/feature/android_visualtrack
origin/master
7.查看所有分支
$ git branch -a
* br-2.1.2.2
master
remotes/origin/HEAD -> origin/master
remotes/origin/br-2.1.2.1
remotes/origin/br-2.1.2.2
remotes/origin/br-2.1.3
remotes/origin/master
8.切换远程分支
$ git branch -a
* master
remotes/origin/HEAD -> origin/master
remotes/origin/Release
remotes/origin/master
$ git checkout -b myRelease origin/Release
Branch myRelease set up to track remote branch Release from origin.
Switched to a new branch 'myRelease'
PS:作用是checkout远程的Release分支,在本地起名为myRelease分支,并切换到本地的myRelase分支
9.合并分支
合并前要先切回要并入的分支
以下表示要把issue1234分支合并入master分支
$: git checkout master
$: git merge issue1234
Merge made by recursive.
README | 1 +
1 files changed, 1 insertions(+), 0 deletions(-)
10.撤消上一次commit的内容(该操作会彻底回退到某个版本,本地的源码也会变为上一个版本的内容)
git reset --hard <commit-id>
以下表示要撤消“update build gradle configuration file”这一次的commit id,返回到"add battery settings ui"这一次的commit id,
xp.chen@YC-JG-YXKF-PC27 MINGW64 /f/ob ((c8303a9...))
$ git log
commit c8303a9e8db2bcf4edb7488e722a380f4e8858ec (HEAD)
Author: xp.chen <xp.chen@yuneec.com>
Date: Sat Oct 28 09:28:51 2017 +0800
update build gradle configuration file
Change-Id: I9ee532fd0d4698613698a64eb754fb98a8559e32
commit 8d8e5ccf24cf6836ab780aa3860270c3876e825a
Author: xp.chen <xp.chen@yuneec.com>
Date: Sat Oct 28 09:02:01 2017 +0800
add battery settigns ui
Change-Id: Ia907ee4e84f54c00a186d31378a7925a6adaba0e
xp.chen@YC-JG-YXKF-PC27 MINGW64 /f/ob ((c8303a9...))
$ git reset --hard 8d8e5ccf24cf6836ab780aa3860270c3876e825a
HEAD is now at 8d8e5cc add battery settigns ui
xp.chen@YC-JG-YXKF-PC27 MINGW64 /f/ob ((8d8e5cc...))
$ git log
commit 8d8e5ccf24cf6836ab780aa3860270c3876e825a (HEAD)
Author: xp.chen <xp.chen@yuneec.com>
Date: Sat Oct 28 09:02:01 2017 +0800
add battery settigns ui
Change-Id: Ia907ee4e84f54c00a186d31378a7925a6adaba0e
11. git commit -m 注释换行
git commit -m 注释可以通过单引号来换行,比如:
$ git commit -m '
> 1.aaaaa
> 2.bbbb
> '
[master b25154b] 1.aaaaa 2.bbbb
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 ss.txt
通过git commit --amend 命令可以查看到刚刚的log信息为
1.aaaaa
2.bbbb
持续更新中...