gpt4 book ai didi

git - 使用 `git commit --amend` 后旧提交会发生什么?

转载 作者:行者123 更新时间:2023-12-02 15:23:52 31 4
gpt4 key购买 nike

假设我们有分支:


A <-- B <-- C

进一步假设我们使用 git commit --amend改变C进入C' :


A <-- B <-- C'

问题 C 发生了什么(字面意思)?该提交是否仍然存在于 git 的对象存储中的某处(它只是悬卡在我们的 master 分支上)?

最佳答案

是的,它存在,如果你知道它的 sha,你就可以做到

git show <SHA>

看到它。

它只是保持“孤儿”状态,最终会被垃圾收集器删除。

最终情况会是

A -- B -- C'
\
\-- C (this commit is unreachable, so it's not shown in normal git logs)

关于垃圾收集器,又名 git gc

Runs a number of housekeeping tasks within the current repository, such as compressing file revisions (to reduce disk space and increase performance) and removing unreachable objects which may have been created from prior invocations of git add.

Users are encouraged to run this task on a regular basis within each repository to maintain good disk space utilization and good operating performance.

Some git commands may automatically run git gc; see the --auto flag below for details. If you know what you’re doing and all you want is to disable this behavior permanently without further considerations, just do:

git config --global gc.auto 0

关于git - 使用 `git commit --amend` 后旧提交会发生什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32141607/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com