Git 常用配置:修改地址 ,提交模板配置

Git 修改地址

1、直接修改远程仓库地址

复制代码
    git remote set-url origin url

2、删除本地远程仓库地址,然后添加新的仓库地址

复制代码
git remote rm origin git remote add origin url

3、修改配置文件

每个仓库在初始化时,都会有一个 .git 的隐藏目录,修改其中的 config 文件中的 url

4、查看远程仓库地址

通过上边修改配置文件,我们知道可以从配置文件中查看远程仓库的地址,同时我们也可以用下边的命令来查看

复制代码
git remote -v

在终端上显示GIT信息

如图显分支信息

第一种方案:

首先查看是否存在~/.bash_profile这个文件

终端指令

复制代码
$~/.bash_profile

如果没有创建

复制代码
$touch ~/.bash_profile

然后修改~/.bash_profile,在文件最后添加

复制代码
# Git branch in prompt.
parse_git_branch() {
    git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
export PS1="\u@\h \W\[\033[32m\]\$(parse_git_branch)\[\033[00m\] $ "

第二种方案:

修改.bashrc脚本,在.bashrc脚本中添加

复制代码
function git_branch {
   branch="`git branch 2>/dev/null | grep "^\*" | sed -e "s/^\*\ //"`"
   if [ "${branch}" != "" ];then
       if [ "${branch}" = "(no branch)" ];then
           branch="(`git rev-parse --short HEAD`...)"
       fi
       echo " ($branch)"
   fi
}
export PS1='\u@\h \[\033[01;36m\]\W\[\033[01;32m\]$(git_branch)\[\033[00m\] \$ '

或是使用 git-prompt.sh

window gitbash 使用

修改git终端闪烁的问题:

复制代码
#第一种方式:在~/.inputrc(如果不存在就创建)中添加
set bell-style none
#第二种方式:修改git/etc/inputrc文件
#none, visible or audible
#set bell-style visible
set bell-style none

修改gitbash 头信息内容

复制代码
## git/etc/bash.bashrc 文件中添加
export PS1="\[\033[32m\]root@~\[\033[33m\]/\W\[\033[36m\]\$(__git_ps1 '(%s)')\[\033[0m\]\$ "

source /etc/bash.bashrc

Git commit 模板设置

1.设置模板路径,其中path就是commit模板路径

复制代码
git config --global commit.template path

2.设置模板使用什么软件打开

复制代码
git config --global core.editor [编辑器名字]

比如

复制代码
git config --global core.editor text

fix(<模块>): <描述>

#<具体描述>

#<问题单号>

# type 字段包含:
# feat:新功能(feature)
# fix:修补bug
# docs:文档(documentation)
# style: 格式(不影响代码运行的变动)
# refactor:重构(即不是新增功能,也不是修改bug的代码变动)
# test:增加测试
# chore:构建过程或辅助工具的变动
# scope:用于说明 commit 影响的范围,比如数据层、控制层、视图层等等。
# subject:是 commit 目的的简短描述,不超过50个字符
# Body:部分是对本次 commit 的详细描述,可以分成多行
# Footer:用来关闭 Issue或以BREAKING CHANGE开头,后面是对变动的描述、以及变动理由和迁移方法

使用示例:

(a.)在/home/xxx目录下创建一个commit.template文件

复制代码
vim commit.template 

【模块名称】: 
【修改描述】: 
【问题/需求单号】:

(b.)设置模板路径

复制代码
git config --global commit.template /home/xxx/commit.template

(c.)设置编辑器

复制代码
git config --global core.editor vim //这里设置vim,也可以设置text,egit等其他编辑器

(d.)修改文件,执行

复制代码
git add .                 // 添加工作区的修改文件到缓存区 
git commit                // 该命令会自动弹出如下弹框,只需编辑后面的内容即可 
git push origin dev       // 推送到远端仓库

gitlab merge 模板

(1.) 在项目的根目录下创建目录:

复制代码
.gitlab/merge_request_templates

(2.)在上述目录中添加模板,文件需要为md格式,如:

复制代码
fixbugs-template.md //修改bugs模板 
feature-template.md //新增特性模板

(3.)模板内容参考

复制代码
【bugs单号】: xxx 
【问题原因】:xxx 
【修改描述】: 本次提交修改了xxx问题 
【修改时间】:2020-11-19 
【修改人】:xx

(4.)合并时选择对应的模板

复制代码
#查看GIT所有配置的命令
git config --list
# 查看GIT全局配置的命令:
git config --global --list
#添加GIT全局配置(HTTPS代理) --system
git config --global https.proxy http://10.224.10.252:808
#删除GIT全局配置
git config --unset --global https.proxy
#  配置GIT第三方编辑器
git config --global core.editor D:/Notepad++/notepad++.exe
相关推荐
打不了嗝 ᥬ᭄1 天前
Git 原理与使用
git·gitee
m0_614619061 天前
花了一下午学 Git,整理了一份学习笔记
笔记·git·学习
AGV算法笔记1 天前
解决Git> git add -A -- fatal: CRLF would be replaced by LF in Test/Test.cpp
git
Dontla1 天前
VSCode插件Git Graph介绍(Git可视化管理分支、可视化Git)
ide·git·vscode
Echoo华地1 天前
用git diff快速比较文件夹差异并生成报告
linux·git·unix·repository·diff·branch
勤劳打代码1 天前
防微杜渐 —— 为什么一次 Sync 会变成一次 merge?
git·团队管理
angushine1 天前
gitlab跨服务器备份
服务器·gitlab·github
dyxal1 天前
Windows 下 Git 离线安装与 VS Code 便携版集成完全指南
windows·git·elasticsearch
K3v1 天前
【git】自动化合并推送脚本
git·自动化
鹓于1 天前
Android APK开发到发布全流程指南
git·github