gpt4 book ai didi

git - git reset --hard 和 git reset --merge 有什么区别

转载 作者:IT王子 更新时间:2023-10-29 00:53:06 29 4
gpt4 key购买 nike

在我的实验中,我没能发现两者之间的任何功能差异

git reset --hard

git reset --merge

使用说明也没有给出任何提示

--hard                reset HEAD, index and working tree
--merge reset HEAD, index and working tree

我经常使用 --hard 选项,所以了解它是如何工作的。 --merge--hard 选项有什么区别?

干杯,奥利

也许这里有一个例子,让我们使用以下序列:

cd git_repo
touch file_one
git add file_one
git commit -m "commit one" # sha1 of 123abc
echo "one" >> ./file_one
git commit -a -m "commit two" # sha1 of 234bcd
echo "two" >> ./file_one
git add . # populate index with a change
echo "three" >> ./file_one # populate working area with a change

如果我现在尝试

git reset --merge 123abc

我明白了

error: Entry 'file_one' not uptodate. Cannot merge.
fatal: Could not reset index file to revision '123abc'

原因是file_one在工作区和索引上都有变化

为了解决这个问题我做了

git add .
git reset --merge 123abc

这次成功了,但是,我得到了与 git reset --hard 相同的结果。索引为空,工作区为空,file_one 为空,与第一次提交后一样。

有人能想出说明差异的步骤吗?

最佳答案

来自 git reset manpage :

--hard    Matches the working tree and index to that of the tree being               switched  to. Any changes to tracked files in the working tree since               <commit> are lost.--merge              Resets the index to match the tree recorded by the named commit, and              updates the files that are different between the named commit and              the current commit in the working tree.

git reset --mergegit reset --hard 的更安全版本,当您的更改和其他人的更改混合在一起时,试图随身携带我们的更改。

关于git - git reset --hard 和 git reset --merge 有什么区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1634115/

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