当前位置:   article > 正文

git commit命令详解_git commit info

git commit info

按照git的步骤,要提交一个新的文件,或者一个修改过的文件分3步

第1步:将文件放入版本库的目录(貌似说的是废话)

第2步:用 git add 文件名(最好是全英文,尤其是在windows下)

第2.5步 用git status 命令 查看状态(这一步是良好的习惯,但不是必要,这样在修改、删除或者新建的文件比较多的时候能够避免错误)

这里具体讲解一下,状态主要分为三种状态

1)Untracked files → 文件未被跟踪;  (即没有用add命令的情况)
2)Changes to be committed → 文件已暂存,这是下次提交的内容;(用add命令之后或者文件被修改了再用add命令)
3) Changes bu not updated → 文件被修改,但并没有添加到暂存区。如果 commit 时没有带 -a 选项,这个状态下的文件不会被提交。(文件被修改但没有用再次add命令)

  1. $git status
  2. # On branch master
  3. # Changes to be committed:
  4. # (use "git reset HEAD <file>..." to unstage)
  5. #
  6. # new file: file2
  7. #
  8. # Changed but not updated:
  9. # (use "git add <file>..." to update what will be committed)
  10. # (use "git checkout -- <file>..." to discard changes in working directory)
  11. #
  12. # modified: file
  13. #
  14. # Untracked files:
  15. # (use "git add <file>..." to include in what will be committed)
  16. #
  17. # file3

上面代码给出的就是这三种状态

从中我们可以看到,如果只将所有被修改或者已删除的且已经被git管理的文档提交倒仓库中如果只是修改或者删除了已被Git 管理的文档,是没必要使用git add 命令的。


第三步:用git commit 命令提交  这里有篇文章讲解的比较好可以参考http://www.cnblogs.com/eddy-he/archive/2012/03/22/git_commit.html

这里有几个命令需要区分

git commit 与 git commit -a

git commit 提交的是暂存区里面的内容,也就是 Changes to be committed 中的文件。

git commit -a 除了将暂存区里的文件提交外,还提交 Changes bu not updated 中的文件。


如果直接运行 git commit 或者 git commit -a 则会进入编辑器进行描述此次更新的注释

一般来说默认是nano编辑器

修改的话有两种方式

一种用命令行git config --global core.editor vim 则修改成vim编辑器,主要对当前用户有效

还有一种是修改配置文件:打开.git/config文件,在core中添加 editor=vim即可。(.git目录的东西一般来说谨慎修改,负责会让版本库出现错误,尤其是windows下!!!!)


一般来说大家都不想进入编辑器中进行修改

所以常用的命令号为 git commit -m 或者 git commit -a -m

具体的实例为

$git commit -a -m "commit info"
这个代码与gitcommit相比快捷方便,但是就是commit信息格式无法控制。


还有一个十分重要的命令行

git commit --amend 一般的网上说明该命令行主要用于修改最后一次commit的信息。

其实还有一个很重要的作用就是修改或取消上一次的提交内容,用于补充文件具体例子如下


比如我们发现漏了 file3 没有提交,我们可以运行一下操作:

  1. $git status
  2. # On branch master
  3. # Untracked files:
  4. # (use "git add <file>..." to include in what will be committed)
  5. #
  6. # file3
  7. nothing added to commit but untracked files present (use "git add" to track)
  8. $git add file3
  9. $git commit --amend
  10. [master 671f5cc] commit --amend, add file3
  11. files changed, 2 insertions(+), 0 deletions(-)
  12. create mode 100644 file2
  13. create mode 100644 file3
  14. $git status
  15. # On branch master
  16. nothing to commit (working directory clean)

当然如果最后一次commit的信息在想修改之前已经push上去了,那。。。。。。

也不是不能修改……比如这篇文章就讲解了怎么修改http://blog.csdn.net/tangkegagalikaiwu/article/details/8542827

不过最好不要出现这样的情况


最后,感谢

http://blog.csdn.net/hudashi/article/details/7664409

http://www.cnblogs.com/eddy-he/archive/2012/03/22/git_commit.html

文章的作者,部分内容转载自上述两篇

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/从前慢现在也慢/article/detail/784771
推荐阅读
相关标签
  

闽ICP备14008679号