Git_ preliminary understanding

G IT Beginners

A: What Git is?
Git is the world's most advanced distributed version control system.
Works / process:

 

Workspace: Workspace
Index / Stage: staging area
Repository: warehouse district (or local warehouse)
Remote: a remote repository

  1. What is SVN ?

SVN is centralized version control system, the repository is focused on the central server, and work time, are used in their computers, so first of all from a central server where to get the latest version, and then to work, finish , we need to finish the job on their own to a central server. Centralized version control system must be networked to work, if it can, the bandwidth is large enough in LAN, fast enough, if in the Internet, if Suman, then wonder.

  1. So git it?

Git is a distributed version control system, then it has no central server, each person's computer is a complete repository, so that when things do not need to work, because the versions are on your own computer. Since everyone's computer has a complete repository, how much how individuals collaborate it? For example, to change their own files on the computer A, the others are changed A file on the computer, then, you just need to give each other their own changes pushed between the two, we can see each other's changed.

  1. In How to install Git on Windows ? 

a) visit the official website: https://git-scm.com/download/win

b)  prompts to install git

c)  the following shall be installed successfully    

d)  will pop up something like a command window, it shows Git installed successfully. as follows:

 

e)  After installation, the last step required is provided, at the command line as follows:

git config --global user.name "JiangtaoQu"

git config --global user.email [email protected]

Because Git is a distributed version control system, you need to fill in as a user name and mailbox identification.

 

 

Note: git config --global parameters, with this parameter, indicating that all of the Git repository on your machine will use this configuration, of course, you can also specify a warehouse for different user name and mailbox.

 

  1. What to do:

a)  Create Repository.

  1. What is the repository? Repository also known as warehouse , the English name repository, you can simply understand a directory, all files in this directory can be inside Git to manage, modify each file, delete, Git can be tracked so that any moment can be traced history, or also the file "restore" at some point in the future.
  2. So create a repository is very simple, as I H disk -> Create an tuTesting under Githua directory repository.

 

 

pwd command is used in the current directory is displayed.

  1. 通过命令 git init 把这个目录变成git可以管理的仓库,如下:

 

 

这时候你当前testgit目录下会多了一个.git的目录,这个目录是Git来跟踪管理版本的,没事千万不要手动乱改这个目录里面的文件,否则,会把git仓库给破坏了。如下:

 

把文件添加到版本库中。
首先要明确下,所有的版本控制系统,只能跟踪文本文件的改动,比如txt文件,网页,所有程序的代码等,Git也不列外,版本控制系统可以告诉你每次的改动,但是图片,视频这些二进制文件,虽能也能由版本控制系统管理,但没法跟踪文件的变化,只能把二进制文件每次改动串起来,也就是知道图片从1kb变成2kb,但是到底改了啥,版本控制也不知道。

 

 

 

b) 下面先看下demo如下演示:
我在版本库tuTesting目录下新建一个记事本文件 tu.txt 内容如下:xxx 
第一步:使用命令 git add tu.txt添加到暂存区里面去。如下:

 

 

如果和上面一样,没有任何提示,说明已经添加成功了。
第二步:用命令 git commit告诉Git,把文件提交到仓库。

注意:git commit –m “此处是提交的自拟注释不是文件名称。”)

 

 

现在我们已经提交了一个tu.txt文件了,我们下面可以通过命令git status来查看是否还有文件未提交,如下:

 

 

说明没有任何文件未提交,但是我现在继续来改下tu.txt内容,比如我在下面添加一行111111333333内容,继续使用git status来查看下结果,如下:

 

 

上面的命令告诉我们 tu.txt文件已被修改,但是未被提交的修改。

接下来我想看下tu.txt文件到底改了什么内容,如何查看呢?可以使用如下命令:

git diff readme.txt 如下:

 

如上可以看到,readme.txt文件内容从一行11111111改成 二行 添加了一行22222222内容。

知道了对readme.txt文件做了什么修改后,我们可以放心的提交到仓库了,提交修改和提交文件是一样的2步(第一步是git add 第二步是:git commit)。

如下:

 

 

 

(注意:修改文件内容后需要重新git add “tu.txt”添加到缓存区)

 

 

再次修改tu.txt文件添加一行内容     最后一次修改)

添加进缓存区 git add “tu.txt”

重新提交(添加注释)   git commit –m “最后修正版2

 

 


现在我已经对tu.txt文件做了三次修改了,那么我现在想查看下历史记录,如何查呢?我们现在可以使用命令 git log 演示如下所示:

 

 

git log命令显示从最近到最远的显示日志,我们可以看到最近三次提交,最近的一次是,增加内容为最后一次修改.上一次是添加内容11113333,第一次默认是 兔兔=兔兔.如果嫌上面显示的信息太多的话,我们可以使用命令 git log –-pretty=oneline 演示如下:(注意是 --)

 

 

现在我想使用版本回退操作,我想把当前的版本回退到上一个版本,要使用什么命令呢?可以使用如下2种命令,第一种是:git reset --hard HEAD^ 那么如果要回退到上上个版本只需把HEAD^ 改成 HEAD^^ 以此类推。那如果要回退到前100个版本的话,使用上面的方法肯定不方便,我们可以使用下面的简便命令操作:git reset --hard HEAD~100 即可。未回退之前的readme.txt内容如下:

 

 

 

五:远程仓库
在了解之前,先注册github账号,由于你的本地Git仓库和github仓库之间的传输是通过SSH加密的,所以需要一点设置:
第一步:创建SSH Key。在用户主目录下,看看有没有.ssh目录,如果有,再看看这个目录下有没有id_rsa和id_rsa.pub这两个文件,如果有的话,直接跳过此如下命令,如果没有的话,打开命令行,输入如下命令:

ssh-keygen -t rsa –C “[email protected]”, 由于我本地此前运行过一次,所以本地有,如下所示:

 

 

 

 

 

id_rsa是私钥,不能泄露出去,id_rsa.pub是公钥,可以放心地告诉任何人。

 

 

 

目前,在GitHub上的这个testgit仓库还是空的,GitHub告诉我们,可以从这个仓库克隆出新的仓库,也可以把一个已有的本地仓库与之关联,然后,把本地仓库的内容推送到GitHub仓库。

 

终端中的编辑器vim的使用

终端命令行中先创建

$ touch a.html

  • 第一步:

$ vim  a.html

初始进入编辑器命令模式

  • 第二步:

键盘上:i

进入编辑模式INSERT

  • 第三步:

键盘左上角:esc

INSERT消失,进入命令模式

  • 第四步:

wq

保存退出

或者

q!

不保存强制退出

  • 第五步:

$ cat  a.html

 

 

Guess you like

Origin www.cnblogs.com/zhichao123/p/11234263.html