Git 命令学习

一/gitlab 新建项目

 

Git global setup

git config --global user.name xxx"
git config --global user.email "xxxx@xxx.com"

Create a new repository

git clone http://xx.xx.xx.xx:8090/xxxx/xxxxx.git
cd project_path
touch README.md
git add README.md
git commit -m "add README"
git push -u origin master

Push an existing folder

cd existing_folder
git init
git remote add origin http://xx.xx.xx.xx:8090/xxxx/xxxxx.git
git add .
git commit -m "Initial commit"
git push -u origin master

Push an existing Git repository

cd existing_repo
git remote rename origin old-origin
git remote add origin http://xx.xx.xx.xx:8090/xxxx/xxxxx.git
git push -u origin --all
git push -u origin --tags

 

二/ master分支的代码领先自己的分支,git 如何把master分支代码合并到自己的分支

    切换到主分支

git checkout master

    使用git pull 把领先的主分支代码pull下来

git pull

    切换到自己的分支

git checkout xxx(自己的分支)

    把主分支的代码merge到自己的分支

git merge master

    为推送当前分支并建立与远程上游的跟踪,使用

git push --set-upstream origin plogic

  然后输入git push --set-upstream origin plogic 这行命令,再然后输入用户名和密码,就push成功了。
以后的push就只需要输入

git push origin

创建ssh 密钥,并链接gitlab

ssh-keygen -t rsa -b 2048 -C "email@example.com"

  会得到下面:

Generating public/private rsa key pair.
Enter file in which to save the key (/home/user/.ssh/id_rsa):

直接回车,在下面处输入设置的密码:

Enter passphrase (empty for no passphrase):
Enter same passphrase again:

2,复制密钥,粘贴到gitlab

xclip -sel clip < ~/.ssh/id_rsa.pub

3, 测试, 输入如下命令及密码

ssh -T git@git_ip

 

三-delete file and filefolder

1、在本地仓库删除指定文件

git rm 文件名名称

2、在本地仓库删除指定文件夹

git rm -r 文件夹/

3、提交修改

git commit -m"删除文件夹"

4、推送到远程仓库

git push origin 远程仓库连接

5、git  rm命令

git rm -h
用法:git rm [<选项>] [--] <文件>...
 
    -n, --dry-run         演习
    -q, --quiet           不列出删除的文件
    --cached              只从索引区删除
    -f, --force           忽略文件更新状态检查
    -r                    允许递归删除
    --ignore-unmatch      即使没有匹配,也以零状态退出

 

四/ git 打tag

 

我们可以创建一个tag来指向软件开发中的一个关键时期,比如版本号更新的时候可以建一个“v2.0”、“v3.1”之类的标签,这样在以后回顾的时候会比较方便。
tag的使用很简单,主要操作有:查看tag、创建tag、验证tag以及共享tag。

查看tag

// 查看tag,列出所有tag,列出的tag是按字母排序的,和创建时间没关系。
$ git tag
v0.1
v1.3
//查看指定版本的tag,git tag -l “v1.4.2.**”
$ git tag -l 'v1.4.2.*'
v1.4.2.1
v1.4.2.2
v1.4.2.3
v1.4.2.4

显示tag信息

//显示指定tag的信息
$ git show v1.4
tag v1.4
Tagger: Scott Chacon <schacon@gee-mail.com>
Date:   Mon Feb 9 14:45:11 2009 -0800

my version 1.4

commit 15027957951b64cf874c3557a0f3547bd83b3ff6
Merge: 4a447f7... a6b4c97...
Author: Scott Chacon <schacon@gee-mail.com>
Date:   Sun Feb 8 19:02:46 2009 -0800

    Merge branch 'experiment'

创建tag

//创建轻量级tag:这样创建的tag没有附带其他信息
git tag v1.0
//带信息的tag:-m后面带的就是注释信息,这样在日后查看的时候会很有用
git tag -a v1.0 -m 'first version'

共享tag

//我们在执行 git push 的时候,tag是不会上传到服务器的,比如现在的github,创建 tag 后 git push ,在github网页上是看不到tag 的,为了共享这些tag,你必须这样:
git push origin v1.0
或者
//将所有tag 一次全部push到github上。
git push origin --tags

删除tag

//删除本地tag
git tag -d v1.0
//删除github远端的指定tag
git push origin :refs/tags/v1.0.0

创建一个基于指定tag的分支

git checkout -b tset v0.1.0

使用git checkout tag即可切换到指定tag,例如:git checkout v0.1.0

切换到tag历史记录会处在分离头指针状态,这个时候修改是很危险的,在切换回主线时如果没有合并,之前的修改提交基本都会丢失,如果需要修改可以尝试git checkout -b branch tag创建一个基于指定tag的分支,例如:git checkout -b tset v0.1.0 这个时候就会在分支上进行开发,之后可以切换到主线合并.

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值