Git 使用日记

Git日常使用

以下内容,均参考官网整理:

Git - Book

1 . 基础操作

1.1 初始化仓库,生成.git文件,

git init

1.2 克隆完整工程

git clone https://github.com/libgit2/libgit2

1.3 跟踪文件并提交

#跟踪指定文件,添加跟踪文件
git add text.txt
git commit -m 'initial project version'

1.4 添加.gitignore 忽略文件

  1. 在git 仓库的根目录下新建一个.gitignore 文件。
  2. 在.gitignore 文件中添加想要忽略的文件或文件夹,.gitignore 文件内默认的相对路径是当前.gitignore 文件所在路径,.gitignore 文件的配置可以使用通配符,具体使用参考官网:
  3. 通过git check-ignore <filename> ,来检查指定的文件或文件夹有没有添加到忽略对象中。
  4. 如果.gitignore 文件没有生效,可以采取以下措施来生效:   
git rm -r --cached .    #删除缓存
git add .
git commit -m "update .gitignore"

     5. 日常格式:

.bin            //以gitignore目录为相对路径。当前目录下.bin目录及其子文件。
*.pro         //当前目录下.pro文件结尾的文件

1.5 添加commit模板文件     

#配置模板文件,commit.template 后面是自己创建的模板文件的绝对路径
 git config --global commit.template  /home/user/work/commit_template 

#配置默认的编辑器,core.editor后面跟的是要设置的编辑器,我这里设置的为vim
git config --global core.editor vim 

1.6 分支创建与合并,远程分支创建与删除

本地分支创建, 创建后直接进入该分支.

git checkout -b newBranch

创建远程分支

git push origin newBranch

切换本地分支到主分支

git checkout master

合并本地分支,首先切换到主分支(或其他分支),合并创建的分支

git merge newBranch

删除本地分支

git branch -d newBranch

删除远程分支

//待验证
git push origin :heads/newbranch

1.7 tag标签创建,删除,同步云端

tag 标签创建

git tag xxx_release

tag 推送到云端

git push origin --tags

删除本地tag

git tag -d xxx.release

删除远程tag

git push origin --tags

1.8 gerrit 设置review地址

// git remote add gerrit ssh://克隆地址,如:
git remote add gerrit ssh://luozc@gerrit.qq.com:29418/D3_AIP_APP

1.9 Git查看本地分支基于哪个分支创建

git reflog show --date=local | grep 分支名

待续....

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值