git 常用指令 Git-查看远程分支、本地分支、创建分支

Git更新远程分支列表

git remote update origin --prune,这里要注意下,如果你的remote branch不是在origin下,按你得把origin换成你的名字。

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 <[email protected]>
Date:   Sat Oct 28 09:28:51 2017 +0800

    update build gradle configuration file

    Change-Id: I9ee532fd0d4698613698a64eb754fb98a8559e32

commit 8d8e5ccf24cf6836ab780aa3860270c3876e825a
Author: xp.chen <[email protected]>
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 <[email protected]>
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信息为

git 切换远程仓库地址

1、切换远程仓库地址:

  • 方式一:修改远程仓库地址

    【git remote set-url origin URL】 更换远程仓库地址,URL为新地址。

  • 方式二:先删除远程仓库地址,然后再添加

    【git remote rm origin】 删除现有远程仓库 
    【git remote add origin url】添加新远程仓库

2、【git remote -v 】查看远程仓库的地址

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 <[email protected]>
Date:   Sat Oct 28 09:28:51 2017 +0800

    update build gradle configuration file

    Change-Id: I9ee532fd0d4698613698a64eb754fb98a8559e32

commit 8d8e5ccf24cf6836ab780aa3860270c3876e825a
Author: xp.chen <[email protected]>
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 <[email protected]>
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信息为

git 切换远程仓库地址

1、切换远程仓库地址:

  • 方式一:修改远程仓库地址

    【git remote set-url origin URL】 更换远程仓库地址,URL为新地址。

  • 方式二:先删除远程仓库地址,然后再添加

    【git remote rm origin】 删除现有远程仓库 
    【git remote add origin url】添加新远程仓库

2、【git remote -v 】查看远程仓库的地址

猜你喜欢

转载自www.cnblogs.com/weizhenlu/p/9228270.html