Git与GitHub

1.git-init

– Create an empty Git repository or reinitialize an existing one
创建一个空的 Git 存储库或重新初始化现有的存储库

        git init                                 /*  初始化本地仓库  */

2.git-status

– Show the working tree status
显示工作树状态

        git status                               /*  查看状态  */

3.git-add

– Add file contents to the index
将文件[README.md]的内容添加到索引

        git add README.md                        /*  添加文件到版本库暂存区  README.md 为要添加的文件  */

4.git-commit

– Record changes to the repository,Create a new commit containing the current
contents of the index and the given log message describing the changes.
将本地的内容提交到索引 -m 后面跟日志内容

        git commit -m "Update README.md"         /*  提交到版本库暂存区  -m '日志内容'  */

5.git-log

– Show commit logs
显示提交的日志信息

        git log                                  /*  显示日志  */

6.git-clone

– Clone a repository into a new directory
将存储库克隆到新目录中

        git clone https://github.com/threadx.git    /*  克隆远程仓库的代码(linux.git)  */

7.git-remote-add-origin

– 将版本库暂存区的内容添加到远程仓库

        git remote add origin https://github.com/threadx.git    /*  把 git commit 到版本库暂存区的代码添加远程仓库 [https://github.com/threadx.git] 远程仓库链接  */

8.git-push

– Update remote refs along with associated objects
更新远程引用以及关联的对象

        git push
        git push origin

9.git-pull

– Fetch from and integrate with another repository or a local branch
从另一个存储库或本地分支获取并集成

        git pull

10.git-diff-HEAD

– Show changes between commits, commit and working tree, etc
Changes in the working tree since your last commit.
本地文件 README.md 与版本库中的 README.md 进行比较

        git diff HEAD -- README.md               /*  对比工作区文件与版本库暂存区文件的不同  */

11.git-reset-HEAD

– Reset current HEAD to the specified state
撤销已经添加到版本库暂存区的文件

        git reset HEAD README.md                 /*  撤销 git add 到暂存区的 README.md 文件  */

12.git reset --hard HEAD^

回退到上一个版本

        git reset --hard HEAD^                   /*  回退到上一个 git commit 的版本,一个 ^ 代表回退次数,回退到上上一个版本:git reset --hard HEAD^^  */
        git reset --hard HEAD~num                /*  回退到倒数第num个版本,num 可以为 1、2、3、、、  */

撤销之前的回退操作

        git reflog                               /*  查看唯一的字符串 开头部分[2903d55]  */
        git reset --hard 2903d55		     /*  2903d55 为想恢复版本的唯一字符串  */
        git log --pretty=oneline		     /*  提交的版本特别多时用于此命令替换 git reflog  */

将本地工作区的内容上传到远程仓库

  第1步:  git init
  第2步:  git add .
  第3步:  git commit -m "First Update commit"
  第4步:  git remote add origin https://github.com/threadx.git     /*  实际远程仓库的链接  */
  第5步:  git push -u origin master

修改本地工作区的文件 [modified: README.md]

  第1步:  git add README.md
  第2步:  git commit -m "Changes committed"
  或者直接:  git commit -a -m "Changes committed"    可以省略 git add 步骤

删除或恢复版本库暂存区的文件

  git restore README.md                          /*  从暂存区删除 README.md 文件  */
  git rm README.md
  git checkout README.md                         /*  恢复从暂存区删除 README.md 文件  */

Git 本地分支操作

  git checkout master                            /*  切换到指定 [master] 的分支  */
  git checkout -b public-preview-v1.0.0          /*  新建分支 public-preview-v1.0.0 并切换到新分支  */
  git branch -d public-preview-v1.0.0            /*  删除指定的分支,在 master 主分支下删除分支 public-preview-v1.0.0  */
  git branch                                     /*  查看所有分支,并且 * 号标记当前所在的分支  */
  git merge public-preview-v1.0.0                /*  合并分支,先切换到 master 主分支,再合并分支 public-preview-v1.0.0  */
  git branch -m | -M old-branch new-branch       /*  重命名分支,如果 new-branch 的分支名已经存在,则需要使用 -M 强制重命名,否则,用 -m 进行重命名  */

Git 远程分支操作,分支 push 与 pull 操作

  git branch -a                                  /*  查看本地与与远程分支  */
  git push origin public-preview-v1.0.0          /*  推送本地分支 public-preview-v1.0.0 到远程仓库  */
  git push origin :remote-branch                 /*  删除远程仓库分支 remote-branch,本地分支未被删除,注意 :号后面不能有空格  */
  git checkout -b local-branch origin/remote-branch    /*  拉取远程仓库分支,并在本地创建分支,  local-branch:本地分支名,remote-branch:远程仓库分支名  */
  
  注意:删除远程仓库的分支之前,先删除本地分支,删除本地分支前必须先切换到 master 主分支

Git 本地分支操作冲突

同一文件 在master 主分支和 branch 分支下都进行了修改,合并这两个分支(branch 分支合并到 master)时会冲突

Git 远程操作冲突,多人协同开发操作

避免冲突的办法,提交前先 git pull,再 git push

Git 标签管理

  git tag tag_name                               /*  新建标签 tag_name,默认为 HEAD  */
  git tag -a tag_name -m "add tag"               /*  添加标签 tag_name,并指定标签描述信息  */
  git tag                                        /*  查看所有标签  */
  git tag -d tag_name                            /*  删除一个本地标签,tag_name 为要删除的标签名  */
  git push origin tag_name                       /*  推送本地标签 tag_name 到远程  */
  git push origin --tags                         /*  推送全部未推送过的本地标签到远程  */
  git push origin :refs/tags/tag_name            /*  删除一个远程标签  */

Documentation

Documentation for this library can be found here: [Link]

Git 配置 SSH Key

git config --global user.name “这里换上你的用户名”
git config --global user.email “这里换上你的邮箱”
ssh-keygen -t rsa -C “这里换上你的邮箱”
拷贝 id_rsa.pub 文件的内容

取消代理
git config --global --unset http.proxy
git config --global --unset https.proxy
使用代理
git config --global http.https://github.com.proxy http://127.0.0.1:7890
git config --global https.https://github.com.proxy https://127.0.0.1:7890

Git 工具 Windows 版本加速下载地址

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值