Git/提交修改:修订间差异

来自康健生活
< Git
Kangkk​(留言 | 贡献)
Kangkk​(留言 | 贡献)
第13行: 第13行:


=== commit ===
=== commit ===
== commit ==
=== rebase ===
=== reset ===
<div class="pageBoxGreen"><code>^</code> 表示前一次。<code>^^^^</code> 等价于 <code>~4</code>。<br>
{{hcdiff|head=|output=<syntaxhighlight lang="bash">
git reset fb69f9d^^^^</syntaxhighlight>|output2=<syntaxhighlight lang="bash">
git reset fb69f9d~4
</syntaxhighlight>}}</div>
取消最后一次 commit。
{{shc|<syntaxhighlight lang="bash">
git reset fb69f9d^
# or
git reset master^
# or
git reset HEAD^</syntaxhighlight>|$|/home/kangkk}}
回退到指定 commit
{{shc|<syntaxhighlight lang="bash">
git reset fb69f9d</syntaxhighlight>|$|/home/kangkk}}
==== --mixed ====
==== soft ====
==== hard ====
=== --amend ===
=== 追加文件到 commit ===
==== reset ====
删除最后一次 commit,重新 commit。
==== --amend --no-edit ====
将文件并入最后一次 commit。使用 <code>--no-edit</code> 标识不进行编辑 commit 信息。
{{shc|<syntaxhighlight lang="bash">
git add src/a.js && \
git commit --amend --no-edit</syntaxhighlight>|$|/home/kangkk}}
== 命令合并 ==
== 命令合并 ==
现在我们将文件 a.js 加入暂存区并提交 commit 信息。
现在我们将文件 a.js 加入暂存区并提交 commit 信息。

2024年3月1日 (五) 06:46的版本

提交

add

参数 描述 示例
. 当前目录全部,递归子目录 git add .
--all 当前项目全部,递归子目录 git add --all
文件相对地址 部分 git add src/a.js

commit

commit

rebase

reset

^ 表示前一次。^^^^ 等价于 ~4。

git reset fb69f9d^^^^
git reset fb69f9d~4

取消最后一次 commit。

/home/kangkk
git reset fb69f9d^
# or
git reset master^
# or
git reset HEAD^

回退到指定 commit

/home/kangkk
git reset fb69f9d

--mixed

soft

hard

--amend

追加文件到 commit

reset

删除最后一次 commit,重新 commit。

--amend --no-edit

将文件并入最后一次 commit。使用 --no-edit 标识不进行编辑 commit 信息。

/home/kangkk
git add src/a.js && \
git commit --amend --no-edit

命令合并

现在我们将文件 a.js 加入暂存区并提交 commit 信息。

git add /src/a.js
git commit -m "edit the file"

可以将存储至暂存区和打 commit 的两个命令进行简化为一行。

git commit -a -m "edit the file"