首页 > 其他 > 详细

git使用

时间:2019-09-03 19:45:58      阅读:82      评论:0      收藏:0      [点我收藏+]

首先大家先明白git不过就是一个版本控制器 还有svn也属于版本控制器中的一种,而github和oschina开源中国 gitee码云 是属于远程仓库(也就是用于保管你的的代码的远程库) 一般来说你放在上面的代码都是开源的,不公开的项目存放是需要费用的,当然你也可以搭建一个属于自己的git仓库git服务器 然后将个人的项目存放在上面

因为我本人也是一个普通的大三学生也即将进入实习,但此前还未使用git多人合作过,但也有大致的了解,接下来我会带领大家学习git

大致流程如下:

注册github账号 下载git

使用ssh密匙

git上配置个人信息

github上创建仓库

git推送项目到仓库上面

还有其他各种操作

github上搭建个人page项目展示(纯静态)

 

 

注册github和下载git软件

1、进入官方网站

https://github.com

技术分享图片

 

2、找到右上角的sign in

注册 填写个人信息即可

 

3、下载软件

上网搜git官网自行下载

 

安装完后可以在桌面看到这个图标

技术分享图片

 

或者单击鼠标右键可以看到

git bash 选项

 

使用密匙ssh登录

在未使用密匙之前每次将项目推送到github的仓库上时候都需要填写账号密码,这换谁都感觉操心所以使用ssh是最好的了

首先如果你是第一次使用git就得先完成以下

 

git init初始化一个仓库 当前路径下会生成一个隐藏文件目录.git这个是一个管理git仓库的文件夹

注意

当前生成的git仓库还是一个空的仓库也就是不属于任何人的仓库

 

 

设置用户账号和邮箱

Git config --global user.name ‘webcyh’

Git config --global user.email ‘1992281294@qq.com’

则下面的是设置编辑器默认使用的vim编辑器有关vim编辑器可以查看我之前编写的vim的使用 这个如果玩的好 鼠标基本用不上了

Git config --global core.editor ‘vim’

接下来是git创建密匙ssh

执行命令

ssh-keygen -t rsa -C "你的邮箱地址" 接着回车

下面出现

技术分享图片

 

 

 中间出现的Enter file inwhich to save 后边写的是你要保存的ssh文件路径

接下来的要求输入passphrase 直接回车就行

 

最后到保存的路径下可以看到两个文件

技术分享图片

 

将pub后缀的文件的内容复制下来

打开github 在管理(setting)当中找到

技术分享图片

 

技术分享图片

 

 

 

再次点击添加密匙

技术分享图片

 

 

将你刚才获取到的ssh密匙贴在上面保存就行

判断是否成功?

git -T git@github.com

技术分享图片

 

 

 看到上面的信息说明你的密匙已经起作用了

接着可以手动更改你当前git上保存的仓库地址后边我会给出命令添加地址的方式

首先在当前目录下查看隐藏的目录可以看到.git 打开可以看到

技术分享图片

 

打开可以看到目录文件如下 

技术分享图片

 

 

 

 简单介绍一下里边文件的用处

 

 

 

这里为了可以查看git的使用可以使用

git --help命令此时,可以看到显示的git的相关参数为了后面的方便使用可以将内容重定向到一个文件夹当中

使用

git --help>>./test.txt 输出内容到指定文件当中

cat test.txt查看文件内容

内容如下

usage: git [--version] [--help] [-C <path>] [-c <name>=<value>]
           [--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
           [-p | --paginate | -P | --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目录的目录)、版本库 、以及暂存区  也称为索引

暂存区位于.git 当中的index

在这里为了更加形象的描述

这里可以将则三部分看成三个目录

工作区、暂存区、版本库

在使用git add -a 或者 git add file1 file2 后暂存区被更新 同时同时工作区修改或者添加的内容被写入对象库当中的一个新的对象当中同时该对象的id被记录在暂存区的index上

使用git commit 提交时 当前暂存区的目录被记录在版本库当中,同时当前master指向的就是暂存区的目录

git reset HEAD 将master指向的目录更新到暂存区 工作区不受影响(因为此时暂存区可能已经更新了但并没有commit 更新到版本库上因此可以使用该命令恢复到上一次的版本 注意此时还没有push到远程库 但此时也算是一个版本了只是尚未开源)

比如当前工作区有以下文件

a.txt b.txt  

 

git使用

原文:https://www.cnblogs.com/webcyh/p/11454695.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!