git基本操作

发布时间:2023年12月31日

git基本操作,没有理论,纯干货,所见即所得。

git账号管理

查看账号

查看当前git用户名: git config user.name
查看当前git邮箱: git config user.email

切换账号

切换git用户名: git config --global user.name "xxx@qq.com"
切换git邮箱: git config --global user.email "xxx@qq.com"

git初始化

命令:git init

示例:
hero@~ /d/git_study
$ git init
Initialized empty Git repository in D:/git_study/.git/

初始化以后当前目录称作工作区(Working Directory) 如:git_study目录.且当前存在一个.git的文件,不属于工作区,称作版本库,版本库中有一个称为stage(或者叫index)的暂存区,还有一个Git为我们自动创建的第一个分支master,以及指向master的一个指针叫HEAD

git状态查看

git status

查看git分支

hero@~ /d/git_study (master)
$ git status
On branch master

No commits yet

nothing to commit (create/copy files and use "git add" to track)

git工作区下文件状态

新建文件mylog.txt,再次查看状态,文件状态untracked files

hero@~ /d/git_study (master)
$ git status
On branch master

No commits yet

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

        mylog.txt

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

git add 命令

git add <file>

示例:将文件添加到git暂存区,文件状态No commits

hero@~ /d/git_study (master)
$ git add mylog.txt

hero@~ /d/git_study (master)
$ git status
On branch master

No commits yet

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

        new file:   mylog.txt

git commit命令

git commit -m "说明信息"

示例:将暂存区中的文件commit到对应分支如:master

hero@~ /d/git_study (master)
$ git commit  -m "add mylog.txt"
[master (root-commit) 745d82d] add mylog.txt
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 mylog.txt

hero@~ /d/git_study (master)
$ git status
On branch master
nothing to commit, working tree clean

hero@~ /d/git_study (master)

文章来源:https://blog.csdn.net/u013713832/article/details/135310443
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。