Git Book读书笔记--git远程仓库&&打标签&&别名

Git Book中文版

git远程仓库&&打标签

  • 查看远程仓库
git remote  # 查看远程git服务器简写,如果你克隆自己的项目,可以看到origin。


git remote -v # 会显示需要读写远程仓库使用的Git保存的简写和对应的URL。

例如:

$ git remote -v

origin  https://github.com/zhang3550545/MyUtils.git (fetch)
origin  https://github.com/zhang3550545/MyUtils.git (push)

添加远程仓库

git remote add <shortname> <url>

从远程仓库中拉取不会自动合并

git fetch [remote-name]

eg:

$ git fetch origin

remote: Counting objects: 3, done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), done.
From https://github.com/zhang3550545/MyUtils
   ad84a77..83ac600  master     -> origin/master

从远程仓库中拉取,会从最初克隆的服务器上抓取数据,会自动尝试合并到当前分支。

git pull 

eg:

$ git pull

remote: Counting objects: 3, done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 1), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), done.
From https://github.com/zhang3550545/MyUtils
   83ac600..ab300a3  master     -> origin/master
Updating ad84a77..ab300a3
Fast-forward
 README.md       | 3 ++-
 settings.gradle | 2 +-
 2 files changed, 3 insertions(+), 2 deletions(-)

推送到远程仓库

git push [remote-name] []branch-name

eg:

$ git push origin master # 推送到master分支

Counting objects: 3, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 371 bytes | 0 bytes/s, done.
Total 3 (delta 2), reused 0 (delta 0)
remote: Resolving deltas: 100% (2/2), completed with 2 local objects.
To https://github.com/zhang3550545/MyUtils.git
   ab300a3..b887f70  master -> master

查看远程仓库

git remote show [remote-name]

eg:

$ git remote show origin

* remote origin
  Fetch URL: https://github.com/zhang3550545/MyUtils.git
  Push  URL: https://github.com/zhang3550545/MyUtils.git
  HEAD branch: master
  Remote branch:
    master tracked
  Local branch configured for 'git pull':
    master merges with remote master
  Local ref configured for 'git push':
    master pushes to master (up to date)

远程仓库的移除与重命名

  • 移除
git remote rm remote_name

git remote remove remote_name

eg:

$ git remote
ok
origin


$ git remote rm ok


$ git remote
origin
  • 重命名
git remote rename origin zhang

eg:将zhang远程库的简写改为z

$ git remote
origin
zhang


$ git remote rename zhang z


$ git remote
origin
z

打标签

列出标签

git tag  # 列出标签

查看标签信息和对应的提交信息

git show version_name

轻量标签

git tag version_name  # 打标签

eg:

git tag v1.1

$ git show v1.1
commit ff2dbc57120798bed2581a2afe0a9ce1792915eb
Author: XXX <XXX@XXX-XXX.com>
Date:   Fri Apr 28 10:20:41 2017 +0800

    2.txt 写入数据

diff --git a/2.txt b/2.txt
index e69de29..085664e 100644
--- a/2.txt
+++ b/2.txt
@@ -0,0 +1 @@
+2.txt <CE>ļ<FE>д<C8><EB>
\ No newline at end of file

打附注标签:-a指定版本,-m版本信息附注。

git tag -a v1.0 -m'v1.0版本'

通过附注标签输出会显示打标签这的信息,日期及附注信息等。
eg:

$ git show v1.0

tag v1.0
Tagger: xxx <xxx@xxx-xxx.com>
Date:   Fri Apr 28 10:11:43 2017 +0800

1.0版本

commit 64644c2ec618962b5a3632cf22c749e90b9f6564
Author: xxx <xxx@xxxx.com>
Date:   Thu Apr 27 14:37:15 2017 +0800

    上一次提交信息有误,2.txt第一次提交确定

diff --git a/2.txt b/2.txt
new file mode 100644
index 0000000..e69de29

共享标签

默认情况下,git push命令并不会传送标签到远程仓库服务器上。在创建完标签后,你必须显示的
推送标签到共享服务器上。如:

 git push origin [tagname]

eg:

 $ git push origin v1.0

Counting objects: 4, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (4/4), 423 bytes | 0 bytes/s, done.
Total 4 (delta 1), reused 0 (delta 0)
remote: Resolving deltas: 100% (1/1), completed with 1 local object.

检出标签

 git checkout -b [branchname] [tagname]

eg:

 $ git checkout -b zhang v1.0
Switched to a new branch 'zhang'

别名

eg:

 git config --global alias.co checkout  # 把checkoout命令改为co

 git congif --global alias.br branch  # 把branch命令改为br

 git config --global alias.ci commit  # 把commit命令改为ci

 git config --global alias.last 'log -1 HEAD'  # 包log -1 HEAD命令改成last。这样就方便的看到最后一次提交记录了

git修改用户名和邮箱

 # 修改用户名
 git config --global user.name you_name

 # 修改邮箱
 git config --global user.email you_emial

Git Book中文版

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值