public:it:git

差别

这里会显示出您选择的修订版和当前版本之间的差别。

到此差别页面的链接

两侧同时换到之前的修订记录 前一修订版
后一修订版
前一修订版
public:it:git [2021/07/27 10:35] – [Tips] oakfirepublic:it:git [2024/05/09 14:34] (当前版本) – [Tips] oakfire
行 6: 行 6:
  
 ===== 二、GIT 与 SVN 的区别 ===== ===== 二、GIT 与 SVN 的区别 =====
-  * GIT 为分布式的,GIT 工程每个副本都是一个备份;而 SVN 是非分布的,依赖一个中心服务器; +  * GIT 为分布式的,GIT 工程每个副本都是一个备份;而 SVN 是非分布的,依赖一个中心服务器; 
-    * SVN 只有一个中心服务器,GIT 可以0个或多个;svn是提交,git是同步;+    * SVN 只有一个中心服务器,GIT 可以0个或多个远端备份;svn是提交,git是同步;
     * SVN 得连接中心服务器才能查看历史log; 而git不用;     * SVN 得连接中心服务器才能查看历史log; 而git不用;
   * GIT 以元数据方式存储(于.git隐藏目录);SVN 以文件方式存储;   * GIT 以元数据方式存储(于.git隐藏目录);SVN 以文件方式存储;
-    * SVN 的分支是一个完整文件目录;而 git 只保持一本地文件目录,切换分支直接改变该目录文件; +    * SVN 的分支是一个完整文件目录;而 git 只保持一本地文件目录,切换分支直接改变该目录文件; 
   * GIT 没有全局唯一版本号;SVN 有;   * GIT 没有全局唯一版本号;SVN 有;
     * git 可以打 tag 来弥补;     * git 可以打 tag 来弥补;
行 38: 行 38:
   * 简单概括:**父项目只记录子模块的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
行 54: 行 54:
 git submodule init git submodule init
 git submodule update git submodule update
 +# 或一条命令循环初始化及更新子模块
 +git submodule update --init --recursive  
 </code> </code>
   * 修改Submodule的内容: <code bash>   * 修改Submodule的内容: <code bash>
-//直接进入子模块文件夹,进行常规git操作+直接进入子模块文件夹,进行常规git操作
 cd your-submodule-folder cd your-submodule-folder
 git add something git add something
行 67: 行 69:
   * 移除Submodule:<code bash>   * 移除Submodule:<code bash>
 # 先砍掉目录 # 先砍掉目录
-git rm --cached [欲移除的目錄] +git rm --cached <欲移除的目录> 
-rm -rf [欲移除的目錄]+rm -rf <欲移除的目录>
 # 修改 .gitmodules,将相关内容移除 # 修改 .gitmodules,将相关内容移除
 vim .gitmodules vim .gitmodules
行 102: 行 104:
   * 增加远程仓库<code bash>git remote add [repo_name] git@remote_repo</code>   * 增加远程仓库<code bash>git remote add [repo_name] git@remote_repo</code>
   * 选择远程仓库push <code bash> git push [repo_name] [branch]</code>   * 选择远程仓库push <code bash> git push [repo_name] [branch]</code>
 +  * 删除远程仓库分支:<code bash>git push origin --delete branchname</code>
 +  * 删除本地的远程分支追踪(比如在远程分支删除后本地''git branch -a''还有遗留remote分支)<code bash>git branch -r -d origin/your_branch_name</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>
行 112: 行 116:
 # tag <<tag>> means the same as refs/tags/<tag>:refs/tags/<tag>. # tag <<tag>> means the same as refs/tags/<tag>:refs/tags/<tag>.
 # Pushing an empty <src> allows you to delete the <dst> ref from the remote repository.</code> # Pushing an empty <src> allows you to delete the <dst> ref from the remote repository.</code>
-  * 删除本地的远程分支追踪(比如在远程分支删除后本地''git branch -a''还有遗留remote分支)<code bash>git branch -r -d origin/your_branch_name</code> 
   * merge 分支后, 如果隐藏了分支的 commit 信息, 具体查看可以使用<code bash>git log --graph</code> 来列出合并分支的 commit , 再一一查看.   * merge 分支后, 如果隐藏了分支的 commit 信息, 具体查看可以使用<code bash>git log --graph</code> 来列出合并分支的 commit , 再一一查看.
   * 撤销 ''git add FILE'' : <code bash>git rm --cached FILE # 撤销文件FILE   * 撤销 ''git add FILE'' : <code bash>git rm --cached FILE # 撤销文件FILE
行 120: 行 123:
 </code> </code>
   * 合并特定的单个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]], :!:如果设为store模式,将在本地明文存储用户密码 +  * 凭证存储: [[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]],  
-  * 打印更多日志:<code>GIT_TRACE=2 GIT_CURL_VERBOSE=1 git clone <repo></code> 详见[[https://git-scm.com/book/en/v2/Git-Internals-Environment-Variables#Debugging|git 环境变量]]+    * 如果设为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 环境变量]] 
 +  * 提交空commit: <code bash>git commit --allow-empty -m "Empty"</code> 
 +  * 修改上一次commit的message: <code bash>git commit --amend -m "new msg" </code> 
 +  * 设置 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> 
 ==== server: gitolite ==== ==== server: gitolite ====
   * [[http://gitolite.com/gitolite/index.html|gitolite docs]]   * [[http://gitolite.com/gitolite/index.html|gitolite docs]]
行 132: 行 144:
 但对使用者来说, 命令的正交性不强这一点, 就造成了使用者需要记住大量单独的命令. 但对使用者来说, 命令的正交性不强这一点, 就造成了使用者需要记住大量单独的命令.
 考虑找个或弄个简化版的本地版本控制系统, 或者做个git的命令包装. 考虑找个或弄个简化版的本地版本控制系统, 或者做个git的命令包装.
 +这篇文章不错:https://www.highflux.io/blog/what-makes-git-hard-to-use
 </WRAP> </WRAP>
  
  • public/it/git.1627353303.txt.gz
  • 最后更改: 2021/07/27 10:35
  • oakfire