目录
创建分支git checkout –b branchname
查看用户名和邮箱git config user.name/user.email
一、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
…