手机版
你好,游客 登录 注册 搜索
背景:
阅读新闻

GitHub秘籍 : Git 篇

[日期:2014-11-17] 来源:Linux中国  作者:Linux [字体:大 中 小]

使用网页查看本地仓库

使用Git的 instaweb 可以立即在 gitweb中浏览你的工作仓库。这个命令是个简单的脚步,配置了gitweb和用来浏览本地仓库的Web服务器。(译者注:默认需要lighttpd支持)

  1. $ git instaweb

执行后打开:

Git instaweb

进一步了解 Git instaweb 命令.

Git配置

所有Git配置都保存在你的.gitconfig 文件中。

Git命令自定义别名

别名用来帮助你定义自己的git命令。比如你可以定义 git a 来运行 git add --all。

要添加一个别名, 一种方法是打开 ~/.gitconfig 文件并添加如下内容:

  1. [alias]
  2. co = checkout
  3. cm = commit
  4. p = push
  5. # Show verbose output about tags, branches or remotes
  6. tags = tag -l
  7. branches = branch -a
  8. remotes = remote -v

...或者在命令行里键入:

  1. $ git config --globalalias.new_alias git_function

例如:

  1. $ git config --globalalias.cm commit

指向多个命令的别名可以用引号来定义:

  1. $ git config --globalalias.ac 'add -A . && commit'

下面列出了一些有用的别名:

别名 Alias命令 Command如何设置 What to Type
git cm git commit git config --global alias.cm commit
git co git checkout git config --global alias.co checkout
git ac git add . -A git commit git config --global alias.ac '!git add -A && git commit'
git st git status -sb git config --global alias.st 'status -sb'
git tags git tag -l git config --global alias.tags 'tag -l'
git branches git branch -a git config --global alias.branches 'branch -a'
git remotes git remote -v git config --global alias.remotes 'remote -v'
git lg git log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit -- git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --"

自动更正

如果键入 git comit 你会看到如下输出:

  1. $ git comit -m "Message"
  2. # git: 'comit' is not a git command. See 'git --help'.
  3.  
  4. # Did you mean this?
  5. # commit

为了在键入 comit 调用 commit命令,只需启用自动纠错功能:

  1. $ git config --global help.autocorrect 1

现在你就会看到:

  1. $ git comit -m "Message"
  2. # WARNING: You called a Git command named 'comit', which does not exist.
  3. # Continuing under the assumption that you meant 'commit'
  4. # in 0.1 seconds automatically...

带颜色输出

要在你的Git命令输出里加上颜色的话,可以用如下命令:

  1. $ git config --global color.ui 1

进一步了解 Git config 命令.

Git资源

TitleLink
Official Git Site http://git-scm.com/
Official Git Video Tutorials http://git-scm.com/videos
Code School Try Git http://try.github.com/
Introductory Reference & Tutorial for Git http://gitref.org/
Official Git Tutorial http://git-scm.com/docs/gittutorial
Everyday Git http://git-scm.com/docs/everyday
Git Immersion http://gitimmersion.com/
Ry's Git Tutorial http://rypress.com/tutorials/git/index.html
Git for Designer http://hoth.entp.com/output/git_for_designers.html
Git for Computer Scientists http://eagain.net/articles/git-for-computer-scientists/
Git Magic http://www-cs-students.stanford.edu/~blynn/gitmagic/

Git参考书籍

TitleLink
Pragmatic Version Control Using Git http://www.pragprog.com/titles/tsgit/pragmatic-version-control-using-git
Pro Git http://git-scm.com/book
Git Internals Peepcode http://peepcode.com/products/git-internals-pdf
Git in the Trenches http://cbx33.github.com/gitt/
Version Control with Git http://www.amazon.com/Version-Control-Git-collaborative-development/dp/1449316387
Pragmatic Guide to Git http://www.pragprog.com/titles/pg_git/pragmatic-guide-to-git
Git: Version Control for Everyone http://www.packtpub.com/git-version-control-for-everyone/book

Linux git命令参数及用法详解 http://www.linuxidc.com/Linux/2012-01/51205.htm

Fedora通过Http Proxy下载Git http://www.linuxidc.com/Linux/2009-12/23170.htm

在Ubuntu Server上安装Git http://www.linuxidc.com/Linux/2009-06/20421.htm

服务器端Git仓库的创建(Ubuntu) http://www.linuxidc.com/Linux/2011-02/32542.htm

Linux下Git简单使用教程(以Android为例) http://www.linuxidc.com/Linux/2010-11/29883.htm

Git权威指南 PDF高清中文版 http://www.linuxidc.com/Linux/2013-10/91053.htm

Git 2分钟指南 http://www.linuxidc.com/Linux/2014-11/109201.htm

Git 的详细介绍:请点这里
Git 的下载地址:请点这里

本文永久更新链接地址:http://www.linuxidc.com/Linux/2014-11/109490.htm

linux
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款