git 版本库的奇技淫巧

发布时间:2024-11-25 08:14

Git版本控制:GitHub的Git教程很实用 #生活技巧# #工作学习技巧# #编程学习资源#

文章目录 前言git配置别名.gitconfig配置别名常用git命令查看远程仓库对应的URL查看git的配置信息查看当前分支最后一次提交的hash清理untrack的文件删除generate的文件和untrack的文件查看远程分支最新hash查看所有branch的分支查看两个commit有冲突的地方处理文件冲突查看工作区的改动和缓存区的改动检查更改文件行末的空格查看提交历史有多个提交,想要回滚定制提交团队协同开发提交命令

前言

git版本控制软件在软件开发中的持续集成过程中有着非常重要的地位,可以很方便的帮助企业管理软件版本。

git配置别名

git config --global alias.co checkout git config --global alias.ci commit git config --global alias.br branch git config --global alias.st status 1234

.gitconfig配置别名

[diff] tool = bc4 [difftool] prompt = false [difftool "bc4"] cmd = "\"c:/program files (x86)/beyond compare 4/bcomp.exe\" \"$LOCAL\" \"$REMOTE\"" [merge] tool = bc [mergetool] prompt = false [mergetool "bc4"] cmd = "\"c:/program files (x86)/beyond compare 4/bcomp.exe\" \"$LOCAL\" \"$REMOTE\" \"$BASE\" \"$MERGED\"" 123456789101112

常用git命令

git fetch origin — 与服务器交互,从服务器上下载最新代码。相当于从远程获取最新版本到本地,不会自动merge,比Git pull更安全些。

git rebase origin/master — 将服务器最新内容合并到本地时使用

git pull –rebase = git fetch origin + git rebase origin/master

git push origin master ------- 慎用!将文件push进repo,这种是不经过code review过程,直接进入authentication repository。

git push origin HEAD:refs/drafts/master // 等同于git push review (alias for refs/drafts/master) , ------- 将文件push进gerrit,会产生链接,走code review流程

查看远程仓库对应的URL

git remote -v 1

查看git的配置信息

git config --global -l git config --list 12

查看当前分支最后一次提交的hash

git branch -v 1

清理untrack的文件

git clean -nfd //f:fource , d: directories and files n: show what would be done 1

删除generate的文件和untrack的文件

rm -rf `git ls-files -o` 1

查看远程分支最新hash

git ls-remote | grep develop/4.x 1

查看所有branch的分支

git branch -a 1

查看两个commit有冲突的地方

git am --show-current-patch 1

处理文件冲突

#在cherry pick的时候通常会遇到merge conflict,解决办法 git mergetool --tool=bc3 //do "module add bcompare" if prompt no bc3 #second method git checkout --conflict=diff3 <fileName> 12345

查看工作区的改动和缓存区的改动

git diff //查看工作区的改动 git show +hash //缓存区的改动 git show --stat //以统计的方式显示缓存区改动 123

检查更改文件行末的空格

git diff --check 1

查看提交历史

#每个提交在一行内显示 git log --oneline #在所有提交中搜索[homepage]的提交 git log --all --grep='homepage' #获取某人的提交日志 git log --author="Alex Guo" 123456789

有多个提交,想要回滚

#获取所有提交历史 git reflog #--soft: 重置commit,但保留add文件 git reset --soft #--mixed: 重置到相应的提交, 回到add之前 git reset HEAD@{2} #--hard: 重置commit,并且丢弃add文件 #......OR...... git reset --hard <hash> //default method 123456789

定制提交

#编辑上次的提交 git commit --amend -m "更好的提交日志" #新加提交文件,日志保持不变 git add . && git commit --amend --no-edit #空提交:用来重新触发CI构建 git commit --allow-empty -m "chore: re-trigger build" 123456

团队协同开发提交命令

#先提交自己的更改 git add -u git ci --amend #用git pull --rebase 命令合并新的patch git pull --rebase ssh://zguoxue@gerrit.testrepo.test:29418/wrat/wrat refs/changes/59/7130659/2 #如果有冲突,用mergetool解决冲突 git mergetool --tool = bc3 #rebase完成之后,会自动生成一个commit,这个commit是不需要的,所以需要回滚commit git reset --soft HEAD^1 #再次重新提交自己的更改 git commit --amend #最后检查没有问题,push git push review 12345678910111213

网址:git 版本库的奇技淫巧 https://www.yuejiaxmz.com/news/view/254376

相关内容

Git 使用技巧:提升工作效率的利器
【狂神说】Git 【Github + Gitee】
git常见错误记录
《淮南子》科技与淫巧 全文、注释、鉴赏
软件开发中的10个最佳实践技巧!
爱奇艺万能联播版本大全
深入学习ArduinoJson库 V6版本
夫妻组织卖淫 莱阳公安端掉“居家式”淫窝
自考笔果题库电脑版
工作&生活工具分享推荐

随便看看