您的位置:首页 > 其它

git基本命令整理

2016-12-06 14:13 323 查看
近期项目需要使用到git进行多人开发。所以对git进行学习。以下是整理的笔记内容

git 配置用户名和邮箱   

git config --global user.name "yourname"

git config --global user.email "youremail"

查看配置信息

git config --list

获取帮助

git help

初始化git仓库

git init      使用后就会产生git文件夹用于记录版本信息

把文件加入版本控制 暂存区

git add *.c      可以添加多个文件

提交文件到项目

git commit -m "initial project version"

从现有的仓库克隆项目文件

git clone git://github.com/schacon/grit.git   后面是你的项目地址

需要自定义项目名称时 在后面加项目名称就OK

检查当前文件状态

git status

查看尚未暂存的文件修改了哪些内容  此时不加参数

git diff

加了 --stged参数以后,可以查看已暂存的文件和上次提交的快照之间的差异

移除文件

rm file   删除工作区的文件

git rm    删除暂存区的文件

移动文件

git mv rename.txt rename   给文件重命名

查看日志

git log

git log -p -2 加-p 参数展开显示每次提交的内容差异 -2显示最近两次

git log --stat 显示简要的增改行数统计

git log --preetty=online 显示ID

选项 说明

    -p 按补丁格式显示每个更新之间的差异。

    --stat 显示每次更新的文件修改统计信息。

    --shortstat 只显示 --stat 中最后的行数修改添加移除统计。

    --name-only 仅在提交信息后显示已修改的文件清单。

    --name-status 显示新增、修改、删除的文件清单。

    --abbrev-commit 仅显示 SHA-1 的前几个字符,而非所有的 40 个字符。

    --relative-date 使用较短的相对时间显示(比如,“2 weeks ago”)。

    --graph 显示 ASCII 图形表示的分支合并历史。

    --pretty 使用其他格式显示历史提交信息。可用的选项包括 oneline,short,full,fuller 和 format(后跟指定格式)。

    

撤销操作

修改最后一次提交

git commit --amend

撤销修改

git checkout -- readme.txt

查看远程仓库

git remote

git remote -v  显示对应的克隆地址

添加远程仓库

git remote add [shortname] [url]:

将远程版本的数据更新后抓取到本地

git fetch 远程主机名

推送数据到远程仓库

git push [remote-name] [branch-name]   如git push origin master

查看远程仓库信息

git remote show origin

远程仓库的删除和重命名

git remote rename pb paul

git remote rm paul

显示已有标签

git tag

git tag -l 'v1.4.2.*'  找出1.4.2相关版本并且列出标签

新建标签

git tag -a v1.4 -m "my version 1.4"

git show v1.4 查看相应标签的版本信息

后期加注标签

git log --pretty=online

git tag -a v1.2 [id]

另外这是全部的git命令:

$ git help

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:

start a working area (see also: git help tutorial)

   clone      Clone a repository into a new directory

   init       Create an empty Git repository or reinitialize an existing one

work on the current change (see also: 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

   rm         Remove files from the working tree and from the index

examine the history and state (see also: 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

collaborate (see also: 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

'git help -a' and 'git help -g' list available subcommands and some

concept guides. See 'git help <command>' or 'git help <concept>'

to read about a specific subcommand or concept.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  git命令