GIT 学习笔记(1)
更新Git:
$ git clone git://git.kernel.org/pub/scm/git/git.git
Git 自带一个 git config 的工具来帮助设置控制 Git 外观和行为的配置变量。 这些变量存储在三个不同的位置:
1./etc/gitconfig 文件: 包含系统上每一个用户及他们仓库的通用配置。 如果使用带有 --system 选项的 git config 时,它会从此文件读写配置变量。
2.~/.gitconfig 或 ~/.config/git/config 文件:只针对当前用户。 可以传递 --global 选项让 Git 读写此文件。
3.当前使用仓库的 Git 目录中的 config 文件(就是 .git/config):针对该仓库。
创建用户
git config --global user.name "username"
git config --global user.email "[email protected]"
再次强调,如果使用了 –global 选项,那么该命令只需要运行一次,因为之后无论你在该系统上做任何事情, Git 都会使用那些信息。 当你想针对特定项目使用不同的用户名称与邮件地址时,可以在那个项目目录下运行没有 –global 选项的命令来配置。
文本编辑器
$ git config --global core.editor emacs
查看配置信息
git config --list
检查版本
git --version
项目管理:
$ mkdir projectname #projectname项目名称
$ cd projectname/ #打开projectname目录
$ git init #生成git目录
$ ls -a #查看内部文件
$ touch txtname #创建文件
$ vim txtname #打开文件
$ rm -rf .git #强制删除.git本地仓库
$ cd .. #回退
常见Git命令
usage: git [--version] [--help] [-C <path>] [-c name=value][--exec-path[=<path>]] [--html-path] [--man-path] [--info-path][-p | --paginate | --no-pager] [--no-replace-objects] [--bare][--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]<command> [<args>]
These are common Git commands used in various situations:
这些是在各种情况下使用的常见Git命令:start a working area (see also: git help tutorial)
启动一个工作区(参见:git help tutorial)
clone Clone a repository into a new directory 克隆一个仓库到新目录 init Create an empty Git repository or reinitialize an existing one 创建一个空的Git存储库或重新初始化现有的存储库
work on the current change (see also: git help everyday)
在当前的变化上工作(参见:git help everyday)
add Add file contents to the index 将文件内容添加到缓存区 mv Move or rename a file, a directory, or a symlink 移动或重命名文件,目录或符号链接 reset Reset current HEAD to the specified state 将当前HEAD重置为指定状态 rm Remove files from the working tree and from the index 从工作区和缓存区删除文件
examine the history and state (see also: git help revisions)
检查历史和状态(参见:git help revisions)
bisect Use binary search to find the commit that introduced a bug 使用二分查找找到引入错误的提交 grep Print lines matching a pattern 打印符合图案的线条 log Show commit logs 显示提交日志 show Show various types of objects 显示各种类型的对象 status Show the working tree status 显示工作区文件的状态
grow, mark and tweak your common history
成长,标记和调整你的共同历史
branch List, create, or delete branches 列出,创建或删除分支 checkout Switch branches or restore working tree files 切换分支或恢复工作区文件 commit Record changes to the repository 记录对存储库的更改 diff Show changes between commits, commit and working tree, etc 显示两颗树之间的差异 merge Join two or more development histories together 合并一个或者多个分支到你已经检出的分支中 rebase Reapply commits on top of another base tip 将提交到某一分支上的所有修改都移至另一分支上 tag Create, list, delete or verify a tag object signed with GPG 创建,列出,删除或验证使用GPG签名的标签对象
collaborate (see also: git help workflows)
合作(参见:git help workflows)
fetch Download objects and refs from another repository 从另一个存储库下载对象和参考 pull Fetch from and integrate with another repository or a local branch 从另一个存储库或本地分支中获取并与其集成 push Update remote refs along with associated objects 更新远程引用以及关联的对象