Fanfou Wiki

我等采石之人,当心怀建造大教堂之愿景。

用户工具

站点工具


git

差别

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

到此差别页面的链接

两侧同时换到之前的修订记录前一修订版
后一修订版
前一修订版
git [2020/12/16 09:24] admingit [2021/07/23 08:51] (当前版本) admin
行 1: 行 1:
-====== 安装 ====== +====== Git ======
-===== Windows =====+
  
 +===== 安装 =====
 +
 +==== Windows ====
   - [[https://git-scm.com/download/win|安装包下载]]   - [[https://git-scm.com/download/win|安装包下载]]
   - 双击安装即可   - 双击安装即可
-===== macOS ===== +==== macOS ==== 
-  - 系统包含 Git+  - 系统包含 Git
   - 重新安装:''brew install git''   - 重新安装:''brew install git''
  
-===== 配置 =====+==== 初始化 ==== 
 +<code bash> 
 +# 配置使用初始分支名 
 +git config --global init.defaultBranch master 
 + 
 +# 检查用户是否混用换行符[false|warn|true] 
 +# false:不做任何检查 
 +# warn:在提交时检查并警告 
 +# true:在提交时检查,如果发现混用则拒绝提交 
 +# 必须使用 true 选项 
 +git config --global core.safecrlf true 
 + 
 +# 用于 CRLF 与 LF 之间的转换 [true|input|false] 
 +# false:不进行转换 
 +# input:在提交时,把 CRLF 转换成 LF;签出时不转换 
 +# true:提交时,把 CRLF 转换成 LF;签出时把 LF 转换成 CRLF 
 +# 必须使用 false 选项,禁止默认转换 
 +git config --global core.autocrlf false 
 + 
 +git config --global pull.rebase false 
 +</code> 
 ===== 全局配置 ===== ===== 全局配置 =====
 <file toml .gitconfig> <file toml .gitconfig>
行 28: 行 51:
 </file> </file>
  
-===== 常用配置命令  =====+===== Windows 解决中文乱码 ===== 
 +  - ''git config --global core.quotepath false'' 
 +  - 在 Git Bash 窗口右键,选择 Options,选择 Text 设置选项,将 Character set 设置为:UTF-8 ; 
 +  - 重新打开 Git Bash 即可。 
 +  - 然后你会发现根本解决不了乱码问题~ 
 + 
 +===== 常用命令 ===== 
 +==== 清理文件 ====
 <code bash> <code bash>
-检查用户是否混用换行符[false|warn|true] +清理未被追踪的文件 
-# false:不做任何检查 +$ git clean -f
-# warn:在提交时检查并警告 +
-# true:在提交时检查,如果发现混用则拒绝提交 +
-# 必须使用 true 选项 +
-git config --global core.safecrlf true+
  
-# 用于 CRLF 与 LF 转换 [true|input|false] +清理未被追踪的文件夹和文件 
-# false:不进行转换 +$ git clean -df 
-input:提交时把 CRLF 转换成 LF签出时换 + 
-true:提交时,把 CRLF 转成 LF;签出时把 LF 转成 CRLF +# 连 gitignore 的 untrack 文件/目录也一起删掉 (慎,一般这个是用来删掉编译出来的 .o文件用的) 
-必须使用 false 选项,禁止默认转换 +$ git clean -xfd 
-git config --global core.autocrlf false+ 
 +# 在用上述 git clean 前墙裂建议加上 -n 参数来先看看会删掉哪些文件,防止重要文件被误删 
 +$ git clean -nf 
 +$ git clean -nfd 
 +$ git clean -nxfd 
 +</code> 
 + 
 +==== 放弃本地修改 ==== 
 +1. 使用 ''git add'' 命令之前 
 +<code bash> 
 +$ git checkout -- filename 
 +</code> 
 + 
 +2. 已经使用 git add 添加文件到缓存区; 
 +<code bash> 
 +# 此命令是取消之前的 ''git add'' 添加缓存操作,并会删除本地所作的修改。 
 +$ git reset HEAD filename 
 +</code> 
 + 
 +==== 分支命令 ==== 
 +1. 查看分支 
 +<code bash> 
 +# 查看本地分支 
 +$ git branch 
 +# 查看远程分支 
 +$ git branch -r 
 +# 查看所有分支 
 +$ git branch -a 
 +</code> 
 +2. 切分支 
 +<code bash> 
 +新建分支 
 +$ git branch branch_name 
 +# 切本地分支 
 +$ git checkout branch_name 
 +# 新建分支并切到新分支 
 +$ git checkout -b branch_name 
 +</code> 
 +3. 删除分支 
 +<code bash> 
 +删除本地分支 
 +$ git branch -d branch_name 
 +# 删除远程分支 
 +$ git branch -r -d origin/branch_name 
 +</code> 
 +4. 关联本地和远程分支 
 +<code bash> 
 +# 远程已有,但本地没有 
 +$ git checkout --track origin/branch_name 
 +# 本地已有,但远程没有 
 +$ git push --set-upstream origin branch_name 
 +</code> 
 +5. 在本地重新拉取远程的分支 
 +<code bash> 
 +# 很多时候,远程分支已经不存在了,但是我们在本地还是可以看到远程分支的信息,此时可以使用下边这条命令重新拉取远程分支 
 +$ git remote prune origin 
 +</code> 
 + 
 +<code bash> 
 +# 是否追踪文件模式 [true|false] 
 +git config core.filemode false
 </code> </code>
  
git.1608081891.txt.gz · 最后更改: 2020/12/16 09:24 由 admin