
检查当前文件状态
- [root@typhoeus79 ice_test_m git_test]# git status
- # On branch master
- nothing to commit (working directory clean)
说明当前git目录很干净,所有已跟踪的文件在上次提交后没有修改过。当前的分支为master
Untracked状态
touch创建一个README文件后
- [root@typhoeus79 ice_test_m git_test]# touch README
- [root@typhoeus79 ice_test_m git_test]# git status
- # On branch master
- # Untracked files:
- # (use "git add <file>..." to include in what will be committed)
- #
- # README
- nothing added to commit but untracked files present (use "git add" to track)
出现Untracked状态,说明有git在之前的提交中没有这些文件。
NewFile状态
使用git add跟踪这个文件
- [root@typhoeus79 ice_test_m git_test]# git add README
- [root@typhoeus79 ice_test_m git_test]# git status
- # On branch master
- # Changes to be committed:
- # (use "git reset HEAD <file>..." to unstage)
- #
- # new file: README
- #
在 “Changes to be committed” 这行下面的,就说明是已暂存状态。
git add 的潜台词就是把目标文件快照放入暂存区域,也就是 add file into staged area,同时未曾跟踪过的文件标记为需要跟踪。
modified状态
编辑README文件,写入新内容
- [root@typhoeus79 ice_test_m git_test]# echo 11 >README
- [root@typhoeus79 ice_test_m git_test]# cat README
- 11
- [root@typhoeus79 ice_test_m git_test]# git status
- # On branch master
- # Changes to be committed:
- # (use "git reset HEAD <file>..." to unstage)
- #
- # new file: README
- #
- # 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: README
- #
出现在 “Changes not staged for commit” 这行下面,说明已跟踪文件的内容发生了变化,但还没有放到暂存区。要暂存这次更新,需要运行 git add 命令
再次运行git add之后,状态如下:
- [root@typhoeus79 ice_test_m git_test]# git add README
- [root@typhoeus79 ice_test_m git_test]# git status
- # On branch master
- # Changes to be committed:
- # (use "git reset HEAD <file>..." to unstage)
- #
- # new file: README
- #
Commit操作-提交更新
- [root@typhoeus79 ice_test_m git_test]# git push
- Everything up-to-date
- [root@typhoeus79 ice_test_m git_test]# git status
- # On branch master
- # Changes to be committed:
- # (use "git reset HEAD <file>..." to unstage)
- #
- # new file: README
- #
紧接着直接push的话,会出现“Everything up-to-date”,但是查看git status,README还一个新文件,只是被commited而已
需要执行一次commit
- [root@typhoeus79 ice_test_m git_test]# git add README
- [root@typhoeus79 ice_test_m git_test]# git status
- # On branch master
- # Changes to be committed:
- # (use "git reset HEAD <file>..." to unstage)
- #
- # new file: README
- #
- [root@typhoeus79 ice_test_m git_test]# git commit -m "commit"
- [master 0ec3465] commit
- 1 files changed, 1 insertions(+), 0 deletions(-)
- create mode 100644 README
- [root@typhoeus79 ice_test_m git_test]# git status
- # On branch master
- # Your branch is ahead of 'origin/master' by 1 commit.
- #
- nothing to commit (working directory clean)
当前工作环境已经clean,branch方式有1个commit
Push操作-推送到远程仓库上
- [root@typhoeus79 ice_test_m git_test]# git push
- Counting objects: 4, done.
- Writing objects: 100% (3/3), 234 bytes, done.
- Total 3 (delta 0), reused 0 (delta 0)
- remote: => Syncing Gitorious... [OK]
- To git@10.210.213.9:code_guosong/git_test.git
- ecc80ec..0ec3465 master -> master
- [root@typhoeus79 ice_test_m git_test]# git status
- # On branch master
- nothing to commit (working directory clean)
上面的1个commit已经没有,回到初始的状态


