小白教程
所有教程
关于
Search
172.69.7.166
172.69.7.166
参数设置
贡献
退出
操作
编辑
移动
保护
信息
历史
删除
查看“Git commit”的源代码
本页内容
上一节:
Git_diff
下一节:
Git_reset
因为以下原因,您没有权限编辑本页:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
{{DISPLAYTITLE:git commit}}[[Category:git basic operations|6]] = git commit 命令 = [[git basic operations|Git 基本操作]] 前面章节我们使用 git add 命令将内容写入暂存区。 git commit 命令将暂存区内容添加到本地仓库中。 提交暂存区到本地仓库中: <sample title="" desc="" lang="shell" hererun="1"> git commit -m [message] </sample> [message] 可以是一些备注信息。 提交暂存区的指定文件到仓库区: <sample title="" desc="" lang="shell" hererun="1"> $ git commit [file1] [file2] ... -m [message] </sample> '''-a''' 参数设置修改文件后不需要执行 git add 命令,直接来提交 <sample title="" desc="" lang="shell" hererun="1"> $ git commit -a </sample> === 设置提交代码时的用户信息 === 开始前我们需要先设置提交的用户信息,包括用户名和邮箱: <sample title="" desc="" lang="shell" hererun="1"> $ git config --global user.name 'xiaobai' $ git config --global user.email test@xiaobai.wang </sample> 如果去掉 --global 参数只对当前仓库有效。 === 提交修改 === 接下来我们就可以对 hello.php 的所有改动从暂存区内容添加到本地仓库中。 以下实例,我们使用 -m 选项以在命令行中提供提交注释。 <sample title="" desc="" lang="shell" hererun="1"> $ git add hello.php $ git status -s A README A hello.php $ git commit -m '第一次版本提交' [master (root-commit) d32cf1f] 第一次版本提交 2 files changed, 4 insertions(+) create mode 100644 README create mode 100644 hello.php </sample> 现在我们已经记录了快照。如果我们再执行 git status: <sample title="" desc="" lang="shell" hererun="1"> $ git status # On branch master nothing to commit (working directory clean) </sample> 以上输出说明我们在最近一次提交之后,没有做任何改动,是一个 "working directory clean",翻译过来就是干净的工作目录。 如果你没有设置 -m 选项,Git 会尝试为你打开一个编辑器以填写提交信息。 如果 Git 在你对它的配置中找不到相关信息,默认会打开 vim。屏幕会像这样: <sample title="" desc="" lang="shell" hererun="1"> # Please enter the commit message for your changes. Lines starting # with '#' will be ignored, and an empty message aborts the commit. # On branch master # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # modified: hello.php # ~ ~ ".git/COMMIT_EDITMSG" 9L, 257C </sample> 如果你觉得 git add 提交缓存的流程太过繁琐,Git 也允许你用 -a 选项跳过这一步。命令格式如下: <sample title="" desc="" lang="shell" hererun="1"> git commit -a </sample> 我们先修改 hello.php 文件为以下内容: <sample title="" desc="" lang="shell" hererun="1"> <?php echo '小白教程:www.xiaobai.wang'; echo '小白教程:www.xiaobai.wang'; ?> </sample> 再执行以下命令: <sample title="" desc="" lang="shell" hererun="1"> $ git commit -am '修改 hello.php 文件' [master 71ee2cb] 修改 hello.php 文件 1 file changed, 1 insertion(+) </sample> [[git basic operations|Git 基本操作]]
返回至“
Git commit
”。
上一节:
Git_diff
下一节:
Git_reset