美文网首页git
Git 运行配置(git config)

Git 运行配置(git config)

作者: michael_jia | 来源:发表于2016-08-12 00:39 被阅读3882次

良好的配置有助于提高效率,减少不必要的错误。把运行配置的相关内容单拎出来放到这里,查找和更新方便。

设置运行环境
git config --global user.name <your name>
git config --global user.email <your_email@example.com>
git config --global push.default simple
git config --global core.quotepath false
git config --global core.editor /usr/bin/vim
git config --global credential.helper store
git config --global credential.helper wincred
git config --global core.ignorecase false
  • core.autocrlf;Win Git Bash 时设置,见 git replacing LF with CRLF
  • user.name;设置你的称呼;
  • user.email;设置你的邮箱;
  • push.default simple;This is the safest option and is suited for beginners. 在 git push 时不必指定 [<repository> [<refspec>...]];
  • git config -l;查看所有的(name.key)/(value) -l | --list
  • git config -unset;Remove the line matching the key from config file.
  • git config -unset-all:Remove all lines matching the key from config file.
  • git config --global core.quotepath false:解决 Windows Git Bash、Linux 下的中文转码问题;
  • git config --global core.editor /usr/bin/vimOS X 下 merge 命令 vi error 问题;通常 core.editor=vim。
  • git config --global credential.helper wincred:Win Git Bash 启用 http/https 协议时设置。
  • git config --global core.ignorecase false
    设置大小写敏感,保持 Mac/Win/Linux一致性;在目录名大小写修改时,git可正常提交;
关于 rebase 和 merge 的设置
  • 为了代码 log 易读,请使用 rebase
git config --global pull.rebase true
git config --global branch.autoSetupRebase always
关于 CRLF 问题的通常做法
  • Windows 下
git config --global core.autocrlf true
  • Linux & Mac
git config --global core.autocrlf input
  • 库 repo 中一定是只用 LF 做行结束符的;因此,完全在 Mac 下开发通常不会带入,但难免和 Win 环境下的同学或者外界交流,还是需要设置 input 的;
设置 .gitattributes 文件指定 CRLF 规则
  • .sh shell 文件是需要 LF 作为行结束符的
    否则使用 scp 在从 Win 向 Linux 传输 shell 文件时,shell 执行有问题,还得使用 dos2unix 小工具进行 额外修复(要么传输前修复,要么传输后修复)。
  • 在 git 库根目录下新增 .gitattributes 文件
*.sh text eol=lf
git add . -u
git commit -m "Saving files before refreshing line endings"
git rm --cached -r .
git reset --hard
git add .
# It is perfectly safe to see a lot of messages here that read
# "warning: CRLF will be replaced by LF in *file*."
git commit -m "Normalize all the line endings"
Git asks for username every time I push

git config credential.helper store
不再需要每次输入账号密码。

如何重新输入账号密码?

使用 http 方式访问 git repo 时,假如你密码忘记了,或者服务端不小心清空了你的账号密码,那么 git 会返回 403,但并没有如你所期弹出输入账号密码的提示框,怎么办

建议
  • Win 下同学,如果只使用 Git Bash 环境开发,完全可以参照 Linux 配置,省却一切麻烦;
  • 开发工具:不论 Zend,Sublime,WebStorm,对于跨平台文件格式的支持都很好;这倒不必担心;
git config 配置文件
  1. 系统级文件 $(prefix)/etc/gitconfig
    本文即 /usr/etc/gitconfig 文件。
    git config --system 用来指定读写系统级文件。初始不存在,若不存在则无影响。
  2. 用户级文件 ~/.gitconfig
    git config --global 指定只操作用户级文件。初始不存在,若不存在则无影响。
  3. Repository 级文件 .git/config
    git config --local 对写操作,则只写入 Repository 级文件(默认行为);对读操作,则只从 Repository 级文件读。
  4. git config --file config-file 则指定 config-file。
  5. ~/.config/git/gitk
    这是 gitk 的配置文件;
  6. git config --get <keyname>:列出 <keyname> 的值;
    注:如果不特别指定哪个配置文件,则依 system/global/local 顺序读取,最后的值覆盖前面的,多值的则合并。
  7. git config --get-all <keyname>
备注
gitk 和 git gui

Git 有很多 GUI 客户端软件。git 包中通常包含 git guigitk 这两个内置 tools。在 gitk 中配合使用 git gui。

Run git gui blame on this line
git gui 的 Edit > Option 将 Default File Contents Encoding 由 cp936 改为 UTF-8

相关文章

  • git备忘

    下载git 初次运行 Git 前的配置 git config --global user.name "

  • Pro Git 学习笔记 (一, 基础)

    初次运行 Git 前的配置 Git的配置通过 git config来完成,有三个等级: | 参数 | 文件路径 |...

  • git常见命令

    1、配置信息(初次运行 Git 前的配置) git config --global user.name "John...

  • Git 基本使用

    基本配置命令 git config --list或git config -l:查看配置git config --g...

  • git 配置

    显示当前的Git配置 $ git config --list 编辑Git配置文件 $ git config -e ...

  • Git(二)Git 常用命令

    配置 git config --list显示当前 Git 配置 git config -e [--global]编...

  • 2016-07-13 Git 起步(二) - 初次运行 Git

    初次运行前配置 Git 自带一个 git config 的工具来设置 控制GIT 的外环和行为的配置变量。这些配置...

  • Git 运行配置(git config)

    良好的配置有助于提高效率,减少不必要的错误。把运行配置的相关内容单拎出来放到这里,查找和更新方便。 Customi...

  • git基础操作

    Git配置 $ git config -l查看当前git配置 git config user.name查看当前用户...

  • Git学习笔记

    初次运行前的配置 Git提供了一个叫做git config的工具(实际是git-config命令, 只不过可以通过...

网友评论

    本文标题:Git 运行配置(git config)

    本文链接:https://www.haomeiwen.com/subject/dvshsttx.html