| 两侧同时换到之前的修订记录 前一修订版 后一修订版 | 前一修订版 |
| public:it:git [2021/12/10 14:44] – [Tips] oakfire | public:it:git [2026/01/05 17:19] (当前版本) – [Usage] oakfire |
|---|
| * SVN 的分支是一个完整文件目录;而 git 只保持一份本地文件目录,切换分支直接改变该目录文件; | * SVN 的分支是一个完整文件目录;而 git 只保持一份本地文件目录,切换分支直接改变该目录文件; |
| * GIT 没有全局唯一版本号;SVN 有; | * GIT 没有全局唯一版本号;SVN 有; |
| * git 可以打 tag 来弥补; | * git 可以打 tag 来弥补;但是 tag 只与 commit id对应,而 commit id 不能保证代码的唯一性(因为不同分支的同一 commit id 之前的提交历史可能不一样),所以要保证 tag 唯一性,可额外人为规定只有主分支打的tag是有效的。 |
| |
| ===== 三、GIT 资料 ===== | ===== 三、GIT 资料 ===== |
| * CentOS yum 默认只有1.7.1 版本, 但像github.com等网站需要高于此版本. 此时需要源码安装升级. | * CentOS yum 默认只有1.7.1 版本, 但像github.com等网站需要高于此版本. 此时需要源码安装升级. |
| * 如果源码安装,[[http://github.com/git/git|github repo]], ''make'', ''make install prefix=/usr'', 如果不添加''prefix=/usr'', 默认会安装在当前home目录. | * 如果源码安装,[[http://github.com/git/git|github repo]], ''make'', ''make install prefix=/usr'', 如果不添加''prefix=/usr'', 默认会安装在当前home目录. |
| | |
| | ==== Tools ==== |
| | * 显示仓库信息[[https://github.com/o2sh/onefetch|onefetch]], 这个不错 |
| |
| ==== Usage==== | ==== Usage==== |
| * [[http://wp.joak.org/?p=62 | Git 博文备查]] | * [[http://wp.joak.org/?p=62 | Git 博文备查]] |
| * [[https://github.com/commitizen/cz-cli | Commitizen:Git 提交信息优化]] | * [[https://github.com/commitizen/cz-cli | Commitizen:Git 提交信息优化]] |
| | * [[https://conventional-branch.github.io/zh/| 分支命名规范]] |
| * [[http://pcottle.github.io/learnGitBranching/|Learning git branching]] | * [[http://pcottle.github.io/learnGitBranching/|Learning git branching]] |
| * [[https://nvie.com/posts/a-successful-git-branching-model/|git flow]],[[https://www.atlassian.com/git/tutorials/comparing-workflows/gitflow-workflow|gitflow-workflow]] | * [[https://nvie.com/posts/a-successful-git-branching-model/|git flow]],[[https://www.atlassian.com/git/tutorials/comparing-workflows/gitflow-workflow|gitflow-workflow]] |
| | * [[https://jvns.ca/blog/2024/01/26/inside-git/|Inside .git]], 介绍 .git 文件夹内容 |
| | * [[https://blog.gitbutler.com/how-git-core-devs-configure-git/| git config 的一些设置技巧]] |
| |
| ==== Ignore ==== | ==== Ignore ==== |
| * [[http://git-scm.com/docs/gitignore|gitignore]] | * [[http://git-scm.com/docs/gitignore|gitignore]] |
| | * 白名单的写法为:<code> |
| | * |
| | |
| | !.gitignore |
| | |
| | # whitelist `src` directories and their children, regardless of place |
| | !src/ |
| | !src/**/ |
| | !src/**/*.h |
| | !src/**/*.cpp |
| | |
| | !/docs/ |
| | !/docs/*.md |
| | </code> |
| ==== Submodule ==== | ==== Submodule ==== |
| * 参考[[http://josephjiang.com/entry.php?id=342|Git Submodule 的認識與正確使用!]] | * 参考[[http://josephjiang.com/entry.php?id=342|Git Submodule 的認識與正確使用!]] |
| * 简单概括:**父项目只记录子模块的commit id**,任何和“子模块”常识违背的额外操作,想想这个就理解了<del>但不能接受</del> | * 简单概括:**父项目只记录子模块的commit id**,任何和“子模块”常识违背的额外操作,想想这个就理解了<del>但不能接受</del> |
| * 新增Submodule:<code bash> | * 新增Submodule:<code bash> |
| git submodule add [repository 位置] [欲放置的位置] # 增加一個新的 submodule | git submodule add <repository 位置> <欲放置的位置> # 增加一個新的 submodule |
| git add .gitmodules [放置的位置] | git add .gitmodules <放置的位置> |
| git commit -m "Add submodule into version control" # 提交修改 | git commit -m "Add submodule into version control" # 提交修改 |
| git submodule init # 初始化.git/config | git submodule init # 初始化.git/config |
| * 移除Submodule:<code bash> | * 移除Submodule:<code bash> |
| # 先砍掉目录 | # 先砍掉目录 |
| git rm --cached [欲移除的目錄] | git rm --cached <欲移除的目录> |
| rm -rf [欲移除的目錄] | rm -rf <欲移除的目录> |
| # 修改 .gitmodules,将相关内容移除 | # 修改 .gitmodules,将相关内容移除 |
| vim .gitmodules | vim .gitmodules |
| * 删除远程仓库分支:<code bash>git push origin --delete branchname</code> | * 删除远程仓库分支:<code bash>git push origin --delete branchname</code> |
| * 删除本地的远程分支追踪(比如在远程分支删除后本地''git branch -a''还有遗留remote分支)<code bash>git branch -r -d origin/your_branch_name</code> | * 删除本地的远程分支追踪(比如在远程分支删除后本地''git branch -a''还有遗留remote分支)<code bash>git branch -r -d origin/your_branch_name</code> |
| | * 同步本地的远程分支追踪<code bash>git remote prune origin</code> |
| * 打tag最好用-a -m ,多一个obj,方便管理 <code bash>git tag -a tagname -m "message" [commit]</code> | * 打tag最好用-a -m ,多一个obj,方便管理 <code bash>git tag -a tagname -m "message" [commit]</code> |
| * 删除远程仓库tag<code bash> | * 删除远程仓库tag<code bash> |
| * 合并特定的单个commit,可使用指令 ''git cherry-pick'' | * 合并特定的单个commit,可使用指令 ''git cherry-pick'' |
| * 凭证存储: [[https://git-scm.com/book/zh/v2/Git-%E5%B7%A5%E5%85%B7-%E5%87%AD%E8%AF%81%E5%AD%98%E5%82%A8|credential.helper]], | * 凭证存储: [[https://git-scm.com/book/zh/v2/Git-%E5%B7%A5%E5%85%B7-%E5%87%AD%E8%AF%81%E5%AD%98%E5%82%A8|credential.helper]], |
| * :!:如果设为store模式,将在本地明文存储用户密码 | * 如果设为store模式,将在本地明文存储用户密码,节省下次输入:<code bash>git config credential.helper store</code> :!:这样会<wrap hi>明文</wrap>保存密码到 '' ~/.git-credentials'' |
| * 打印更多日志:<code bash>GIT_TRACE=2 GIT_CURL_VERBOSE=1 git clone <repo></code> 详见[[https://git-scm.com/book/en/v2/Git-Internals-Environment-Variables#Debugging|git 环境变量]] | * 打印更多日志:<code bash>GIT_TRACE=2 GIT_CURL_VERBOSE=1 git clone <repo></code> 详见[[https://git-scm.com/book/en/v2/Git-Internals-Environment-Variables#Debugging|git 环境变量]] |
| * 提交空commit: <code bash>git commit --allow-empty -m "Empty"</code> | * 提交空commit: <code bash>git commit --allow-empty -m "Empty"</code> |
| * 修改上一次commit的message: <code bash>git commit --amend -m "new msg" </code> | * 修改上一次commit的message: <code bash>git commit --amend -m "new msg" </code> |
| * 保存用户名和密码, 节省下次输入:<code bash>git config credential.helper store</code> <wrap hi>注意这样会明文保存密码到</wrap> '' ~/.git-credentials'' | * 设置 vim 为默认编辑器:<code bash>git config --global core.editor "vim"</code> |
| | * 删除某文件的所有历史记录,[[https://blog.csdn.net/yxpandjay/article/details/111275665|参考]]: |
| | * 查找大文件:'' git rev-list --objects --all | grep "$(git verify-pack -v .git/objects/pack/*.idx | sort -k 3 -n | tail -5 | awk '{print$1}')" '' |
| | * 从历史记录删除:'' git filter-branch -f --index-filter 'git rm --cached --ignore-unmatch "your/big.file"' HEAD --all '' |
| | * 显示差异时忽略行尾空格差异: <code bash>git diff --ignore-space-at-eol</code> |
| | * git log 中文显示为尖括号码,修正方式:''export LESSCHARSET=utf-8'' |
| ==== server: gitolite ==== | ==== server: gitolite ==== |
| * [[http://gitolite.com/gitolite/index.html|gitolite docs]] | * [[http://gitolite.com/gitolite/index.html|gitolite docs]] |
| 但对使用者来说, 命令的正交性不强这一点, 就造成了使用者需要记住大量单独的命令. | 但对使用者来说, 命令的正交性不强这一点, 就造成了使用者需要记住大量单独的命令. |
| 考虑找个或弄个简化版的本地版本控制系统, 或者做个git的命令包装. | 考虑找个或弄个简化版的本地版本控制系统, 或者做个git的命令包装. |
| | 这篇文章不错:https://www.highflux.io/blog/what-makes-git-hard-to-use . |
| | 这个可借鉴:https://github.com/jj-vcs/jj . |
| </WRAP> | </WRAP> |
| |