git的使用方法,如何配置

2025-05-21 15:33:30
推荐回答(1个)
回答(1):

使用git 自从git-1.5.4 , 'git-xyz' 这种用法就不提倡了,而推荐 'git xyz' 风格。 git 的后续版本中将在 make install 时不再安装 'git-xyz' 这些 hardlinks 。 当如果执行 git --exec-path 输出的目录中依然有 git-xyz 这些脚本,你还是可以把这个路径加到 PATH 环境变量中, 这样还能够使用 git-xyz 形式的脚本。 config ------ 我的一些简单的配置: $ git-config user.name "Jike Song" $ git-config user.email [email]albcamus@gmail.com[/email] $ git-config core.editor vim $ git-config core.pager "less -N" $ git-config color.diff true // 显示 diff 时色彩高亮 $ git-config alias.co checkout // 给 git checkout 取个别名,这样只输入 git co 即可 $ git-config sendemail.smtpserver /usr/bin/msmtp 注意,这会在当前 repository 目录下的 .git/config 中写入配置信息。 如果 git-config 加了 --global 选项,配置信息就会写入到 ~/.gitconfig 文件中。 因为你可能用不同的身份参与不同的项目,而多个 项目都用 git 管理,所以建议不用 --global 配置。 $ git-val -l // 列出 git 变量 init ---- $ git-init-db // 创建一个 .git/ 目录,初始化一个空的 git 仓库 //这个目录在git-clone时也会创建。也就是说clone时会自动初始化git //仓库里需要的东西 clone ----- $ git-clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git [dir name] [dir name] 是你想让这个仓库叫什么名字。 如果不指定,就会等同于目标仓库的名字。 注意,这种 git server 形式的 repository ,都有一个 filename.git 文件; 而对于 *.git 的操作,也可以 针对.git 所在的目录: $ mkdir tmp/ $ cd tmp/ $ git-clone ~/Sources/linux-2.6 或者通过 ssh : $ git-clone [email]arc@host.xyz.com[/email]:/home/arc/Sources/linux-2.6 此时当前目录下有一个 .git/ 目录 . 以下我们都在 linux-2.6/ 下演示: 使用git 自从git-1.5.4 , 'git-xyz' 这种用法就不提倡了,而推荐 'git xyz' 风格。 git 的后续版本中将在 make install 时不再安装 'git-xyz' 这些 hardlinks 。 当如果执行 git --exec-path 输出的目录中依然有 git-xyz 这些脚本,你还是可以把这个路径加到 PATH 环境变量中, 这样还能够使用 git-xyz 形式的脚本。 config ------ 我的一些简单的配置: $ git-config user.name "Jike Song" $ git-config user.email [email]albcamus@gmail.com[/email] $ git-config core.editor vim $ git-config core.pager "less -N" $ git-config color.diff true // 显示 diff 时色彩高亮 $ git-config alias.co checkout // 给 git checkout 取个别名,这样只输入 git co 即可 $ git-config sendemail.smtpserver /usr/bin/msmtp 注意,这会在当前 repository 目录下的 .git/config 中写入配置信息。 如果 git-config 加了 --global 选项,配置信息就会写入到 ~/.gitconfig 文件中。 因为你可能用不同的身份参与不同的项目,而多个 项目都用 git 管理,所以建议不用 --global 配置。 $ git-val -l // 列出 git 变量 init ---- $ git-init-db // 创建一个 .git/ 目录,初始化一个空的 git 仓库 //这个目录在git-clone时也会创建。也就是说clone时会自动初始化git //仓库里需要的东西 clone ----- $ git-clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git [dir name] [dir name] 是你想让这个仓库叫什么名字。 如果不指定,就会等同于目标仓库的名字。 注意,这种 git server 形式的 repository ,都有一个 filename.git 文件; 而对于 *.git 的操作,也可以 针对.git 所在的目录: $ mkdir tmp/ $ cd tmp/ $ git-clone ~/Sources/linux-2.6 或者通过 ssh : $ git-clone [email]arc@host.xyz.com[/email]:/home/arc/Sources/linux-2.6 此时当前目录下有一个 .git/ 目录 . 以下我们都在 linux-2.6/ 下演示: pull ---- $ git-pull // 更新本地的 git tree 。 如果自从你 clone 了 linus tree 之后, linus tree //有新的改动,那么把这些更改更新到你的本地tree中 //类似于cvs update pull ---- FYI: git-clone 和 git-pull 都会默认调用 git-merge 。 FYI: 每天 git-pull 更新技巧: 1) git-describe ,例如目前是 v2.6.26-rc8-12 2) git-pull -v 3) git-describe ,例如是 v2.6.26-rc8-22 4) git-log -p -10 查看变化 diff ---- $ git-diff /* 列出自己本地的 tree 中已修改、但却未 commit 的改动 这也是产生 patch 的方式 ( 用来提交的 patch 需要先 commit 到自己的 tree 里, 然后git-format-patch) 。 注意,使用 git-diff 产生的 patch 都应该在 patch(1) 时指定 -p1 ,或者直接使用 git-apply 打补丁 */ 选项: --color diff 语法高亮 ( 可以 git-config color.diff true) --ignore-space-at-eol 忽略行尾的 whitespace -b --ignore-space-change 忽略行尾的 whitespace ,并且认为所有的 whitespace 都是一样的 -w --ignore-all-space 比较两行的时候,完全忽略 whitespace 。这样,即使是一行有很多 whitespaces ,另一行文字一样但是没有 whitespace , git 也认为这两 行内容一致。 $ git-pull // 更新本地的 git tree 。