GIT笔记命令行(1)

时间:2021-08-03 13:14:42

Git简单易用,只要输入git就可以列出他的所有参数

 C:\Users\spu>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: 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命令可以分为短和长选项。例如:

git commit  -m "hello git"

git commit --message="hello git"

以上两条命令式等价的

1.Git入门

有两种简历git版本库的技术。可以从头开始创建,用现有的内容填充它,或者可以clone一个已有的版本库,从一个空的版本库比较简单,所有从空的版本库开始吧。

  1.1 创建一个初始版本库

  

 mkdir ~\public
cd ~\public
echo 'hello git' > index.html
git init

  git init将public目录转化为了git版本库。

  git不关心你是从一个空白的目录还是一个装满目录的文件开始的。在这两种情况下将目录转换为GIT版本库是完全一样的。

  为了显示目录是一个git版本库。git init创建了一个隐藏的.git目录。git将所有修订信息都放在这唯一的顶层.git目录中。

  1.2 将文件添加进版本库

  

 git add index.html
git commit -m 'init'
git status

  如果目录中有很多文件,可以用git add . 来添加进版本库。

  git将add、remove和commit分开,以避免频繁的变化。

  add仅仅只是把改变暂存在了本地。commit才是上传了改变。

  

  在add后,如果运行git status 可以查看git下一次将会把index.html上传给版本库

  除了原数据以外,git每次提交的时候,还会包括一些元数据,类似日志信息和作出本次变更的作者。

 

  如果仅仅只是运行git commit ,系统会调用设定好的编辑器来让你编辑