GIT(02)正向状态流转

状态流转图


在这里插入图片描述

状态:未修改&已修改


  • 工作区与仓库保持一致
  • 文件增删改,变为已修改状态,新建一个text.txt文件
  • 修改了ReleaseNote.txt 文件
git status

On branch bthss_V3.0.4
Changes not staged for commit:   // 已修改,未暂存的文件
  (use "git add <file>..." to update what will be committed)   
  (use "git checkout -- <file>..." to discard changes in working directory)

        modified:   ReleaseNote.txt

Untracked files:                   // 新增的文件,未追踪的
  (use "git add <file>..." to include in what will be committed)

        test.txt

no changes added to commit (use "git add" and/or "git commit -a")

状态:已暂存(git add)


  • git add ,变为已暂存状态,提交到暂存区
// 提交
$ git add .

// 查看状态
$ git status
On branch bthss_V3.0.4
Changes to be committed:    // 暂存待提交
  (use "git reset HEAD <file>..." to unstage)

        modified:   ReleaseNote.txt  // 修改
        new file:   test.txt            // 新增

状态:已提交(git commit)


  • git commit,变为已提交状态,提交到本地仓库
    • Git 提供了一个跳过使用暂存区域的方式, 只要在提交的时候,给 git commit 加上 -a 选项
    • Git 就会自动把所有已经跟踪过的文件暂存起来一并提交,从而跳过 git add 步骤
$ git commit -m "test message"
[bthss_V3.0.4 7ef3873] test message
 2 files changed, 2 insertions(+), 1 deletion(-)
 create mode 100644 test.txt
  • 查看状态
$ git status
On branch bthss_V3.0.4
Your branch is ahead of 'origin/bthss_V3.0.4' by 2 commits.
  (use "git push" to publish your local commits)

nothing to commit, working tree clean

状态:已推送(git push)


  • git push,变为已推送状态,推送到远程仓库
    • push 指定服务器,提交远程分支
$ git push origin bthss_V3.0.4

// 结构
Counting objects: 6, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (4/4), done.
Writing objects: 100% (6/6), 474 bytes | 474.00 KiB/s, done.
Total 6 (delta 2), reused 2 (delta 0)
remote:
remote: To create a merge request for bthss_V3.0.4, visit:
remote:   http://git.cnsuning.com/bthss/bthss_git/merge_requests/new?merge_request%5Bsource_branch%5D=bthss_V3.0.4
remote:
To http://git.cnsuning.com/bthss/bthss_git.git
   e0c7639..584fb03  bthss_V3.0.4 -> bthss_V3.0.4
  • 查看状态
$ git status

On branch bthss_V3.0.4
Your branch is up to date with 'origin/bthss_V3.0.4'.

nothing to commit, working tree clean

猜你喜欢

转载自blog.csdn.net/yanbin0830/article/details/88746025