Git-查看远程分支、本地分支、创建分支

 

1.查看本地分支

$ git branch
* br-2.1.2.2
  master

2.查看远程分支

$ git branch -r
  origin/HEAD -> origin/master
  origin/feature/IOS_visualtrack
  origin/feature/android_visualtrack
  origin/master

3.查看所有分支

$ 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

4.切换远程分支

$ 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分支

5.合并分支

合并前要先切回要并入的分支

以下表示要把issue1234分支合并入master分支

$: git checkout master
$: git merge issue1234
Merge made by recursive.
 README |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

6.撤消上一次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

7. 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

 

posted @ 2017-09-27 09:27  夜行过客  阅读(163711)  评论(0编辑  收藏  举报