美文网首页
git基本操作与常用命令

git基本操作与常用命令

作者: bearPotMan | 来源:发表于2019-03-30 17:17 被阅读0次

1. git基本操作

1.1 客户端安装

官网下载git客户端 并完成安装,详细过程不再赘述!

启动 Git Bash 检验。
命令:git 或者 git --version

wj@localhost MINGW64 /d
$ git --version
git version 2.20.1.windows.1

1.2 git 用户信息配置

  1. 配置用户信息

    命令:git config --global user.name "你的名字"
    git config --global user.email "你的邮箱"

wj@localhost MINGW64 /d
$ git config --global user.name "wangjun"

wj@localhost MINGW64 /d
$ git config --global user.email "wangjun9406@163.com"
  1. 查看配置信息

    命令:git config --global user.name

    git config --global user.email

wj@localhost MINGW64 /d
$ git config --global user.name
wangjun

wj@localhost MINGW64 /d
$ git config --global user.email
wangjun9406@163.com
  1. 修改配置信息并查看
wj@localhost MINGW64 /d
$ git config --global user.name "wj"

wj@localhost MINGW64 /d
$ git config --global user.name
wj

wj@localhost MINGW64 /d
$ git config --global user.email "2370959316@qq.com"

wj@localhost MINGW64 /d
$ git config --global user.email
2370959316@qq.com

1.3 创建本地库并初始化

命令:git init

wj@localhost MINGW64 /d
$ cd workspace/

wj@localhost MINGW64 /d/workspace
$ mkdir git-learning

wj@localhost MINGW64 /d/workspace
$ cd git-learning/

wj@localhost MINGW64 /d/workspace/git-learning
$ git init
Initialized empty Git repository in D:/workspace/git-learning/.git/

1.4 添加文件至缓存区

主要命令(添加文件至缓存区):git add yourfile

辅助命令(查看当前仓库/分支状态):git status

wj@localhost MINGW64 /d/workspace/git-learning (master)
$ touch README.md

wj@localhost MINGW64 /d/workspace/git-learning (master)
$ vim README.md

wj@localhost MINGW64 /d/workspace/git-learning (master)
$ git status
On branch master

No commits yet

Untracked files:
  (use "git add <file>..." to include in what will be committed)

        README.md

nothing added to commit but untracked files present (use "git add" to track)

wj@localhost MINGW64 /d/workspace/git-learning (master)
$ git add README.md

wj@localhost MINGW64 /d/workspace/git-learning (master)
$ git status
On branch master

No commits yet

Changes to be committed:
  (use "git rm --cached <file>..." to unstage)

        new file:   README.md

1.5 提交缓存区文件至本地库

命令:git commit -m "本次提交说明"

wj@localhost MINGW64 /d/workspace/git-learning (master)
$ git commit -m "add README.md file"
[master (root-commit) 0fd2779] add README.md file
 1 file changed, 1 insertion(+)
 create mode 100644 README.md

wj@localhost MINGW64 /d/workspace/git-learning (master)
$ git status
On branch master
nothing to commit, working tree clean

1.6 本地库与远程库同步

命令:git remote add origin 仓库地址

wj@localhost MINGW64 /d/workspace/git-learning (master)
$ git remote add origin https://github.com/bearPotMan/git-learning.git

1.7 推送本地库内容至远程库

命令:git push -u origin master

wj@localhost MINGW64 /d/workspace/git-learning (master)
$ git push -u origin master
Enumerating objects: 3, done.
Counting objects: 100% (3/3), done.
Writing objects: 100% (3/3), 252 bytes | 252.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To https://github.com/bearPotMan/git-learning.git
 * [new branch]      master -> master
Branch 'master' set up to track remote branch 'master' from 'origin'.

以上就是最基本的第一次记录提交!

之后的文件的修改与提交使用的命令主要有三个:

  • git add file

  • git commit -m "本次提交说明"

  • git push -u origin master

2. git 常用命令

  • git status:查看当前仓库/分支文件提交状态

  • git checkout -- file:撤销工作区的修改,在下一次 add 操作之前执行该命令才有效

  • git add file:添加文件至缓存区

  • git reset HEAD file:撤销缓存区的修改

  • git commit -m "本次提交说明":提交缓存区文件至本地仓库

  • git push -u origin master:推送本地仓库内容至远程仓库 master 分支

  • git branch:查看当前分支

  • git branch dev:创建 dev 分支

  • git checkout dev:切换至 dev 分支

  • git log:查看提交历史记录

  • git reflog:查看命令历史记录

  • git clone https://github.com/bearPotMan/git-learn:克隆仓库

  • git pull origin master:dev:将远程 master 分支拉取到本地 dev 分支

    ...

其他命令后续用的比较熟练了再更新吧!

我是bearPotMan,一个经验不足的十八线演(码)员(农)。
Know everything,control everything!

相关文章

  • git常用命令

    初始配置 常用命令 git操作原则 vim基本操作

  • Git 命令初级了解

    Mac下Git常用命令之基本操作(github、gitlab通用) 无论是学习还是生活中,掌握基本的git命令,以...

  • GIT 常用

    git基本操作 创建README文件 可以选择先看这个基本上都有了(CSDN)git 常用命令和Gerrit的联合...

  • Git使用教程

    本文为Git基本操作与常用命令的后续教程。在上篇教程中,主要介绍了Git的安装与简单命令,而本文将在上文的基础上进...

  • docker常用命令总结

    参考链接 Docker 常用命令与操作 docker常用命令总结——安装、镜像、容器基本操作

  • 深入了解Git

    git基本命令还可以参考Pro Git;以下是mac系统终端操作,常用命令可以参考http://www.jians...

  • git 其他使用操作(二)

    Git基本常用命令如下:

  • 真 git 操作大全 不会就看

    git 常用命令git 远程操作git 撤销操作 推酷git大全 react router4 中文文档 koa 简...

  • Git基本操作与常用命令

    简介 Git是一个分布式版本控制系统 Git可以在Liunx、Mac、Windows这几大平台上正常运行 Git工...

  • git基本操作与常用命令

    1. git基本操作 1.1 客户端安装 官网下载git客户端 并完成安装,详细过程不再赘述! 启动 Git Ba...

网友评论

      本文标题:git基本操作与常用命令

      本文链接:https://www.haomeiwen.com/subject/bqdsbqtx.html