git status简单用法

来源:互联网 发布:banner请求网络图片 编辑:程序博客网 时间:2024/05/17 01:10

git status可以用来查看仓库的状态,这个命令是一个很有用的命令,在用GIT的过程中,会出现各种意想不到的情况,原因是我们反复提交和修改。git status可以帮助我们快速的知道当前的GIT状态。命令如下:

[root@localhost gender]# git status# On branch master# Your branch is ahead of 'origin/master'by 1 commit.## Changed but not updated:#  (use "git add <file>..." to update what will becommitted)#  (use "git checkout -- <file>..." to discard changes inworking directory)##       modified:   server.c#no changes added to commit (use "gitadd" and/or "git commit -a")[root@localhost gender]#

上面的输出提示你下面的信息,Changedbut not updated,表示我们改动了server.c但是没有更新快照,此时我们应该执行git add server.c(或者git add .来更新快照)。执行如下:

[root@localhost gender]# git add server.c[root@localhost gender]# git status# On branch master# Changes to be committed:#  (use "git reset HEAD <file>..." to unstage)##       modified:   server.c#[root@localhost gender]#

又有事了,输出的Changes to becommitted表示我们的改动已经准备好了,随时可以提交,我们只要用git commit命令提交就可以了。

执行如下:

[root@localhost gender]# git commit -m"no modify"(此处省去95个字) [root@localhost gender]# git status# On branch master# Your branch is ahead of 'origin/master'by 1 commit.#nothing to commit (working directory clean)[root@localhost gender]#

现在就是很干净的状态了。


有一个问题需要注意,就是如果Changedbut not updated之后,执行git add ./ ,但之后又修改了这个文件,那么会同时出现Changedbut not updated和Changes to becommitted。

原创粉丝点击