<分区>
Git 的优势之一是,因为它使用指针操作,所以撤消大量任务相对容易,包括 deleting a commit or commits。或 creating and deleting remote branches .在许多情况下,您真正需要做的就是正确地将当前分支的 HEAD 指针重置为所需的位置,瞧,步骤撤消。这涵盖了相当广泛的案例。
除了删除整个存储库或错误的推送之外,在标准 Git 存储库中无法撤消或极难撤消的最重要的操作是什么?
标签 git
<分区>
Git 的优势之一是,因为它使用指针操作,所以撤消大量任务相对容易,包括 deleting a commit or commits。或 creating and deleting remote branches .在许多情况下,您真正需要做的就是正确地将当前分支的 HEAD 指针重置为所需的位置,瞧,步骤撤消。这涵盖了相当广泛的案例。
除了删除整个存储库或错误的推送之外,在标准 Git 存储库中无法撤消或极难撤消的最重要的操作是什么?
最佳答案
到目前为止,我在 git 新手中遇到的最常见的“难以撤消”错误是滥用 git stash
,因为 git stash pop
git stash
并不总是可逆的| .考虑:
git init /tmp/trash && cd /tmp/trash # make a new repo
echo A > A # create a file
git add A
git commit -m "Initial commit" # add and commit it
echo B > A # ... now change it
git stash # ... and stash it
echo C > A # and change it and commit it again
git add A
git commit -m "Another commit"
git stash pop # now pop the stash
pop
将尝试自动 merge A
并且会引发冲突,但你不能通过点击 git stash
退出流行音乐再次。这是一个相当简单的示例,但如果您经常存储大量更改并频繁切换不同的分支,则很容易陷入困境。我相信git stash drop
也是永久性的,也就是说,如果你放错了藏品,就没有安全网。
一般来说,使用stash
它的设计目的是:存储脏工作索引以跳到另一个分支,修复错误,提交,推送,然后跳回原始状态。如果您尝试使用它来管理跨多个分支的大量更改,它不可避免地会在您不加注意的情况下咬住您。
关于git - Git 中有哪些难以/不可能撤消的操作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16324923/