git
差别
这里会显示出您选择的修订版和当前版本之间的差别。
| 后一修订版 | 前一修订版 | ||
| git [2020/12/16 09:12] – 创建 admin | git [2021/07/23 08:51] (当前版本) – admin | ||
|---|---|---|---|
| 行 1: | 行 1: | ||
| - | ====== | + | ====== |
| - | ===== Windows | + | |
| + | ===== 安装 ===== | ||
| + | |||
| + | ==== Windows ==== | ||
| - [[https:// | - [[https:// | ||
| - 双击安装即可 | - 双击安装即可 | ||
| + | ==== macOS ==== | ||
| + | - 系统已包含 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 | ||
| + | </ | ||
| + | |||
| + | ===== 全局配置 ===== | ||
| + | <file toml .gitconfig> | ||
| + | [user] | ||
| + | name = where.liu | ||
| + | email = liuzhaowei55@gmail.com | ||
| + | [core] | ||
| + | quotepath = false | ||
| + | autocrlf = false | ||
| + | safecrlf = true | ||
| + | longpaths = true | ||
| + | [credential] | ||
| + | helper = manager | ||
| + | [i18n] | ||
| + | commitencoding = utf-8 | ||
| + | logoutputencoding = utf-8 | ||
| + | [i18n " | ||
| + | encoding = utf-8 | ||
| + | </ | ||
| + | |||
| + | ===== Windows 解决中文乱码 ===== | ||
| + | - '' | ||
| + | - 在 Git Bash 窗口右键,选择 Options,选择 Text 设置选项,将 Character set 设置为:UTF-8 ; | ||
| + | - 重新打开 Git Bash 即可。 | ||
| + | - 然后你会发现根本解决不了乱码问题~ | ||
| + | |||
| + | ===== 常用命令 ===== | ||
| + | ==== 清理文件 ==== | ||
| + | <code bash> | ||
| + | # | ||
| + | $ git clean -f | ||
| + | |||
| + | # | ||
| + | $ git clean -df | ||
| + | |||
| + | # | ||
| + | $ git clean -xfd | ||
| + | |||
| + | # | ||
| + | $ git clean -nf | ||
| + | $ git clean -nfd | ||
| + | $ git clean -nxfd | ||
| + | </ | ||
| + | |||
| + | ==== 放弃本地修改 ==== | ||
| + | 1. 使用 '' | ||
| + | <code bash> | ||
| + | $ git checkout -- filename | ||
| + | </ | ||
| + | |||
| + | 2. 已经使用 git add 添加文件到缓存区; | ||
| + | <code bash> | ||
| + | # 此命令是取消之前的 '' | ||
| + | $ git reset HEAD filename | ||
| + | </ | ||
| + | |||
| + | ==== 分支命令 ==== | ||
| + | 1. 查看分支 | ||
| + | <code bash> | ||
| + | # 查看本地分支 | ||
| + | $ git branch | ||
| + | # 查看远程分支 | ||
| + | $ git branch -r | ||
| + | # 查看所有分支 | ||
| + | $ git branch -a | ||
| + | </ | ||
| + | 2. 切换分支 | ||
| + | <code bash> | ||
| + | # 新建分支 | ||
| + | $ git branch branch_name | ||
| + | # 切换本地分支 | ||
| + | $ git checkout branch_name | ||
| + | # 新建分支并切换到新分支 | ||
| + | $ git checkout -b branch_name | ||
| + | </ | ||
| + | 3. 删除分支 | ||
| + | <code bash> | ||
| + | # 删除本地分支 | ||
| + | $ git branch -d branch_name | ||
| + | # 删除远程分支 | ||
| + | $ git branch -r -d origin/ | ||
| + | </ | ||
| + | 4. 关联本地和远程分支 | ||
| + | <code bash> | ||
| + | # 远程已有,但本地没有 | ||
| + | $ git checkout --track origin/ | ||
| + | # 本地已有,但远程没有 | ||
| + | $ git push --set-upstream origin branch_name | ||
| + | </ | ||
| + | 5. 在本地重新拉取远程的分支 | ||
| + | <code bash> | ||
| + | # 很多时候,远程分支已经不存在了,但是我们在本地还是可以看到远程分支的信息,此时可以使用下边这条命令重新拉取远程分支 | ||
| + | $ git remote prune origin | ||
| + | </ | ||
| + | |||
| + | <code bash> | ||
| + | # 是否追踪文件模式 [true|false] | ||
| + | git config core.filemode false | ||
| + | </ | ||
| + | |||
git.1608081152.txt.gz · 最后更改: 2020/12/16 09:12 由 admin
