Git&Gerrit常用操作

目录

一、Gerrit基本使用

凭证管理

二、Git常用操作

全局设置

设置用户名和邮箱

创建版本库git init

提交

添加文件到仓库git add filename

提交并添加信息git commit –m”message”

版本回退git reset --hard num

分支管理

查看分支git branch

创建分支git checkout –b branchname

切换分支git checkout branchname

删除分支git branch –d branchname

合并分支git merge branchname

标签管理

标签查看git tag

添加标签git tag tagname

标签删除git tag –d tagname

远程操作

代码克隆git clone

设置远程仓库地址git remote

拉取并合并git pull

拉取git fetch

推送git push

查询

查询变更记录git log –n

查看用户名和邮箱git config user.name/user.email

查看所有配置git config –list


一、Gerrit基本使用

凭证管理

在使用http克隆等操作时,如未在添加凭证,需要添加,凭证的用户名和密码查看路径为,setting-HTTP Credentials,username直接可以查看,凭证需要点击GENERATE NEW PASSWORD。

二、Git常用操作

全局设置

设置用户名和邮箱

$ git config --global user.email "xx@xx.com"

$ git config --global user.name "xx"

创建版本库git init

$ git init

Initialized empty Git repository in G:/SourceCode/GitTest/learngit/.git/

查看隐藏文件ls –ah
$ ls -ah

./  ../  .git/

提交

添加文件到仓库git add filename

可以添加多个文件

$ git add main.c readme.txt

提交并添加信息git commit –m”message”

$ git commit -m"add 2 files"

[master (root-commit) cc6539b] add 2 files

 2 files changed, 0 insertions(+), 0 deletions(-)

 create mode 100644 main.c

 create mode 100644 readme.txt

版本回退git reset --hard num

$ git reset --hard 142b883bd0d3f603180

HEAD is now at 142b883 The first modified

分支管理

查看分支git branch

$ git branch

* master

创建分支git checkout –b branchname

XXX@DESKTOP-XXX MINGW64 /g/SourceCode/GitTest/learngit (master)

$ git checkout -b branch1

Switched to a new branch 'branch1'

XXX@DESKTOP-XXX MINGW64 /g/SourceCode/GitTest/learngit (branch1)

切换分支git checkout branchname

XXX@DESKTOP-XXX MINGW64 /g/SourceCode/GitTest/learngit (branch1)

$ git checkout master

Switched to branch 'master'

XXX@DESKTOP-XXX MINGW64 /g/SourceCode/GitTest/learngit (master)

删除分支git branch –d branchname

注意不能删自己当前的分支。

XXX@DESKTOP-XXX MINGW64 /g/SourceCode/GitTest/learngit (branch2)

$ git branch -d branch1

Deleted branch branch1 (was 142b883).

合并分支git merge branchname

A分支合并B分支内容

切换到A分支

Git merge B

标签管理

标签查看git tag

$ git tag

tag1

添加标签git tag tagname

$ git tag tag1

标签删除git tag –d tagname

$ git tag -d tag1

Deleted tag 'tag1' (was 142b883)

远程操作

代码克隆git clone

git clone <版本库的网址>

设置远程仓库地址git remote

git remote -v   //查看修改前的仓库

git remote set-url origin xxx     //xxx代表新的仓库地址

git remote -v   //查看修改后的仓库

拉取并合并git pull

git pull

拉取git fetch

git fetch

区别:git pull = git fetch + git merge

推送git push

查询

查询变更记录git log –n

$ git log -2

commit cc6539b3c45c4f146edbcaae242964aca6e7ec3f (HEAD -> master)

Author: xxx <xxx>

Date:   Tue Nov 29 11:03:47 2022 +0800

    add 2 files

查看用户名和邮箱git config user.name/user.email

$ git config user.name

xxx

$ git config user.email

xx.xx@xx.com

查看所有配置git config –list

$ git config --list

diff.astextplain.textconv=astextplain

filter.lfs.clean=git-lfs clean -- %f

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值