zoukankan      html  css  js  c++  java
  • git简单入门

      

      首先下载安装git,完成后打开git bash,可以先输入:git help 简单了解一下有哪些命令.....

    1、配置git,在git bash窗口中输入下面两行命令:

      git config --global user.name "user_name"

      git config --global uer.email "name@example.com"

      红色文字部分根据个人信息修改(下同)

      --global参数表示当前计算机上将要创建的所有仓库都使用这个配置。

    2、创建路径:mkdir dir_name

    3、跳转到制定目录:cd dir_name

    4、显示当前工作路径: pwd

    5、将当前目录变成git可以管理的仓库:git init

    6、添加并提交修改:

      git add file_name

      git commit -m "added a file"

    7、查看状态:git status

    8、查看修改前后的变化:git diff

    9、查看提交记录:

      git log

    让结果只显示一行的命令

      git log --pretty=oneline

    或者先配置

      git config format.pretty oneline

    另查看分支图:

      git log --graph

    10、回到过去:

      退回上一版本:git reset --hard head^

      退回上上一版本:git reset --hard head^^

      退回上...(N个)一版本:git reset --hard head~N

    11、回到过去或未来:

    (1)获取历次commit 的 id 号:git reflog

    (2)git reset --hard commit_id

    12、撤销指定文件的修改(包括删除):

    (1)撤销在工作区的修改(即让文件回到最近一次git commitgit add时的状态):git checkout -- filename

      其中 -- 表示在当前分支下,而不是转换到新的分支

    (2)撤销在暂存区及工作区的修改(即让文件回到最近一次git commit时的状态):git reset head filename

    13、与本地仓库与GitHub 仓库的关联:

      一个简单的方法:在GitHub上创建新的仓库后,会跳转到对应的仓库。我们根据 Quick setup 的提示进行操作即可,即将对应的命令行复制、粘贴到git bash窗口上

    14、branch的操作:

    (1)创建并跳转到新的branch:

      git checkout -b branch_name

    相当于:

      git branch branch_name

      git checkout branch_name

    (2)跳转到指定branch (包括master):

      git checkout branch_name

    (3)将分支推送到远程仓库:

      git push origin branch_name

    (4)删除branch:

      已合并分支删除:git branch -d branch_name   或   git checkout -d branch_name

      未合并分支删除:git branch -D branch_name   或 git checkout -D branch_name

    (5)查看所有分支:

      git branch

    15、更新本地仓库至最新改动:

      git pull

    16、合并制定分支到当前分支:

      git merge branch_name

    加上 --no-ff 参数表示禁用Fast forward,可以保留分支历史:

      git merge --no-ff branch_name

    若出现冲突,则需要修改文件然后再合并;改完之后执行:

      git add file_name

    合并前可先检查分支的差异:

      git diff source_branch target_branch

    17、获取远程仓库的最新版本并覆盖本地版本:

      git fetch origin

    并将本地主分支指向它:

      git reset --hard origin/master

    18、标签操作:

    (1)创建标签:git tag v1.0 commit_id

    (2)显示指定标签版本:git show tag_name

    19、打开图形化git:

      gitk

     20、工作现场的操作:

    (1)保存工作现场:git stash

    (2)查看:git stash list

    (3)恢复: git stash apply

    (4)删除:git stash drop

    (5)恢复并删除:git stash pop

    本文地址:http://www.cnblogs.com/laishenghao/p/5500835.html

    作者博客:( •̀ ω •́ )y

  • 相关阅读:
    前端
    pymysql
    Linux下PostgreSQL 的安装与配置
    PostgreSQL 连接问题 FATAL: no pg_hba.conf entry for host
    PostgreSQ 连接问题 FATAL: no pg_hba.conf entry for host
    中文环境下PostgreSQL的使用
    初学者遇到的PostgreSQL字符集问题的解决
    PostgreSQL 图形化客户端工具有哪些
    PostgreSQL 图形化客户端工具的使用技巧你都get了吗?
    PostgreSQL新手教程
  • 原文地址:https://www.cnblogs.com/laishenghao/p/5500835.html
Copyright © 2011-2022 走看看