zoukankan      html  css  js  c++  java
  • git简单使用(上篇)

    一、安装git软件

    1.git下载地址:链接:http://pan.baidu.com/s/1o8AKGyQ 密码:r7rk

    安装着三个.exe文件,安装成功后在桌面鼠标右键会看到:git clone,TortoiseGit,然后选择TortoiseGit中->setting-

    >选择语言——>简体中文,然后确定(TortoiseGit-Language使用自行选择),git就这么简单安装成功啦!

    二、git常用命令操作文件

    2.windows(开始)->git->gitBash

    3.mkdir iGit//在c:UsersAdministrator盘创建iGit文件

    使用命令:cd iGit进入iGit文件目录下

      git init // 初始化空的仓库(empty Git repository),且在当前目录下回出现.git文件默认隐藏的

    4.添加文件在 iGit文件下面

    5.git add 文件名 // 没有任何是输出

    6.git commit -m "描述" // 把文件提交到仓库

    7.git status // 查看git的状态

    8.git diff // 查看哪些文件被改变了,如果有文件没提交可以执行第5步

    9.git log // 查看git提交日志记录

    如果先一次输出的信息太多,可以使用git log --pretty=online,只输出commit id和提交注释了。

    在Git中,用HEAD表示当前版本,上一个版本就是HEAD^,上上一个版本就是HEAD^^,当然往上100个版本写100个^比

    较容易数不过来,所以写成HEAD~100。

    git的管理是修改,每次git add 命令后都会把工作区的修改放入暂存区。

    10.git reset --hard HEAD^ // 向后回退上一个版本或者多个版本Git提供了一个命令git reflog用来记录你的每一次命令

    11.$ git reset --hard 3628164 // 向前走到未来版本,3628164 是用git reflog查看的commit id

    12.$ git checkout -- readme.txt // 工作区的文件修改进行撤销修改

    13.$ git rm test.txt // 删除没用的文件

    错删了文件:$ git checkout -- test.txt 恢复文件

    三、使用git操作github

    第一步:创建SSH Key。在用户主目录下,看看有没有.ssh目录,如果有,再看看这个目录下有没有id_rsa和id_rsa.pub这两

    个文件,如果已经有了,可直接跳过下一步。如果没有,打开Shell(Windows下打开Git Bash),创建SSH Key:

    14.$ ssh-keygen -t rsa -C "xiazhongwei@able-elec.com"

    第二步:登录github官网,打开“Account settings”,“SSH Keys”页面:

    然后,点“Add SSH Key”,填上任意Title,在Key文本框里粘贴id_rsa.pub文件的内容:

    15.$ git remote add origin git@github.com:izhongwei/iGit.git //在GitHub上的这个iGit仓库还是空的,

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

    GitHub仓库。

    如果出现错误:fatal: remote origin already exists.

    使用命令:$ git remote rm origin 

    然后再执行14步

    16.$ git push -u origin master //本地库的内容推送到远程,用git push命令,实际上是把当前分支master推送到远程,

    一次需要加-u,以后就不需要了

    $ git push origin master // 以后用这个名利就可以

    数据密码:12345678 

    如果出现错误:

    ssh: Could not resolve hostname github: Name or service not known

    fatal: The remote end hung up unexpectedly

    使用命令run this :

    git remote set-url origin git@github.com:izhongwei/iGit.git

    如果出现错误:fatal:error: failed to push some refs to 'git@github.com:izhongwei/iGit.git'

    hint: Updates were rejected because the remote contains work that you do

    hint: not have locally. This is usually caused by another repository pushing

    hint: to the same ref. You may want to first integrate the remote changes

    hint: (e.g., 'git pull ...') before pushing again.

    hint: See the 'Note about fast-forwards' in 'git push --help' for details.

    远程存在已经提交的文件,需要先pull下来:

    使用命令:$ git pull --rebase origin master

    17.$ git push -u origin master // 上传成功

    18、上面讲的都是在本地先创建git仓库然后上传项目到github,下面我们来讲讲如何下载别人已经上传到github上的项目下载

    到本地:

    • 可以先进入电脑d:/跟目录下
    • 选择鼠标右键,选择Git Bash Here 会弹处git命令窗口:
    • 执行命令: git clone git@github.com:izhongwei/JDBC.git 
    • 然后等下载好了,到d盘根目录下就会看到从github上下克隆下来的项目了
    • 就是这么简单,赶快动手试试吧

    详细文档请参阅:

    http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000

  • 相关阅读:
    ssm框架搭建出现的异常:The import org.springframework cannot be resolved
    ssm框架中的乱码问题的解决
    json语法和使用
    AJAX概述和简单使用
    JavaScript给动态插入的元素添加事件绑定
    Vue常用开源项目汇总
    ERROR in Template execution failed: ReferenceError: htmlwebpackPlugin is not defined
    Error: webpack.optimize.UglifyJsPlugin has been removed, please use config.optimizat
    vue-loader was used without the corresponding plugin. Make sure to include VueLoaderPlugin
    Error: Chunk.entrypoints: Use Chunks.groupsIterable and filter by instanceof Entrypoint instead
  • 原文地址:https://www.cnblogs.com/ablejava/p/5594021.html
Copyright © 2011-2022 走看看