Git Product home page Git Product logo

git-abc's Introduction

git-abc

下面介绍经常用到的且最基本的git 命令

仓库管理

创建本地仓库

  • git init
mkdir git-abc
cd git-abc
git init

image-20210331222402099

添加远程分支

  • git remote add <shortname> <url>
git remote add origin https://github.com/simplezhao/git-abc.git

抓取远程代码

  • git fetch <remote>
git fetch origin

image-20210331223237496

查看某个远程仓库

  • git remote show <remote>
git remote show origin

image-20210331223628444

同步远程分支

  • git checkout -b <branch> <remote>
git checkout -b main origin/main

image-20210331224921389

代码管理

查看当前分支状态

  • git status
  1. 修改readme.md文件
git status

提示文件被修改

image-20210331225856222

  1. 新增一个readme_en.md文件
git status

提示有未跟踪的文件

image-20210331230055526

添加文件

  • git add . 添加所有文件

  • git add <file>添加指定文件

# 添加所有文件
git add .

添加成功后,显示准备提交的文件

image-20210331230400289

提交文件

  • git commit -a 在默认编辑器内增加本次提交内容
  • git commit -m <message>简短提交
git commit -m "update readme file and add new readme for english version"

image-20210331230900239

推送到远程分支

  • git push <shortname> <branch>
git push origin main

image-20210331231029318

查看提交记录

  • git log
git log

image-20210331231130554

代码合并

多人开发同一个项目,需要共同维护同一个代码库,假如每个人负责独立的模块,不会涉及到代码冲突

某次提交时,提示如下问题

image-20210331232246543

这是因为远程分支要优先本地的分支,需要先执行git pull,然后在执行git push命令

git pull origin main
git push origin main

执行pull时会提示Merge信息

image-20210331232418971

完成并退出编辑后,提示pull信息

image-20210331232514825

再次执行git push origin main,显示提交成功

image-20210331232632195

分支管理

创建新的分支

  • git branch <branch>
git branch hotfix
git checkout hotfix

分支合并

在上一步操作,因为系统出现bug,紧急创建一个分支,然后在这个分支上进行修复,修改测试验证完毕后,从hotfix分支合并到main分支

git checkout main
git merge hotfix

image-20210331235235214

分支删除

  • git branch -d <branch>
git branch -d hotfix

打标签

  • git tag

  • git tag -a <version> -m <message>

通过git tag查看仓库内已经存在的标签列表

创建标签

git tag -a '1.0' -m "first version"

也可以使用轻量级标签

git tag 1.0-a

共享标签

默认情况下 git push命令不会把标签传送到远程仓库,必须显式地推送标签到服务器,类似于推送代码

git push <shortname> <tagname>

如果想一次推送多个标签,可以使用如下命令

git push <shortname> --tags

git push origin 1.0
git push origin --tags

推送指定标签

image-20210401001342160

推送所有标签

image-20210401001405265

git 配置

使用git config -l 查看当前仓库配置

配置全局信息

git config --global user.name "yourname"
git config --global user.email "youremail"

配置当前仓库信息

和全局区别在于去掉--global标记

git config user.name "yourname"
git config user.email "youremail"

参考

[1] Book: Pro Git

git-abc's People

Contributors

simplezhao avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.