如何强制git恢复
我的git日志如下所示:如何强制git恢复,git,Git,我的git日志如下所示: commit b265eb43abd7704ed2560cca7c635dbd47b677b0 Date: Sun Feb 25 10:20:58 2018 -0500 added C3 commit 536d071bf99059ff8b519ae96ce6e97d92fbc7d7 Date: Sat Feb 24 20:50:15 2018 -0500 added B2 commit 6e46e4ff4135b4df55866a5df9
commit b265eb43abd7704ed2560cca7c635dbd47b677b0
Date: Sun Feb 25 10:20:58 2018 -0500
added C3
commit 536d071bf99059ff8b519ae96ce6e97d92fbc7d7
Date: Sat Feb 24 20:50:15 2018 -0500
added B2
commit 6e46e4ff4135b4df55866a5df9af963e3d6ff218
Date: Sat Feb 24 11:07:58 2018 -0500
added a
commit 93ad202a08660a62f76496d728a3a89d727350a9
Date: Sat Feb 24 11:05:56 2018 -0500
first commit
我想撤消以前的提交并返回提交6e46e4ff4135b4df55866a5df9af963e3d6ff218。但是,我想保留历史记录,不想从git日志中删除添加的C3和B2,这样就排除了git重置-硬6e46e4ff4135b4df55866a5df9af963e3d6ff218
我在网上读了一些书,人们说git revert是实现这一点的完美工具。我尝试使用git revert 6e46e4ff4135b4df55866a5df9af963e3d6ff218并查看以下内容
error: could not revert 6e46e4f... added a
hint: after resolving the conflicts, mark the corrected paths
hint: with 'git add <paths>' or 'git rm <paths>'
hint: and commit the result with 'git commit'
我打开了要还原的文件,看到了以下内容:
Test
<<<<<<< HEAD
adding A
adding B
adding C
=======
>>>>>>> parent of 6e46e4f... added a
有人告诉我这意味着我有合并冲突。但是我不想将项目的当前状态与项目的旧状态合并-我想用项目的旧状态替换项目的当前状态
有没有办法简单地用一个旧的提交来替换项目的当前状态,而这就是新的提交?我可以手动执行以下操作:1执行git签出,2将签出的项目复制到备份目录,3执行主文件夹中的git签出主机,3删除主文件夹中的所有文件,用旧提交的备份替换它们。但是我更愿意学习如何用git的方式来做。我还希望避免使用分支解决方案,因为我想学习如何使用git revert——如果在这个非常基本、简单、规范的示例中不能使用它,那么它可以用于什么呢?revert撤消提交;它不会回到某一点 如果您在b265eb4上仍然有一棵干净的树,只需这样做: 我的意思是,在您开始返回到尝试还原之前的位置之前,您可能希望git重置硬b265eb4
git revert b265eb4
git revert 536d071
然后检查它是否像这样工作
git diff 6e46e4f
您应该具有与该提交中相同的文件,但存在错误,然后在历史记录中恢复
。。。。或者,如果要在一次提交中撤消两次错误提交
git reset --hard 6e46e4f # to make the files how you want them
git reset b265eb4 # to get back to the last commit
git diff # should see local changes that undo everything in the last two commits
git add -A
git commit -m"undo last couple commits"
git diff 6e46e4f # the state of the files should be the commit you wanted to go back to
恢复撤消提交;它不会回到某一点 如果您在b265eb4上仍然有一棵干净的树,只需这样做: 我的意思是,在您开始返回到尝试还原之前的位置之前,您可能希望git重置硬b265eb4
git revert b265eb4
git revert 536d071
然后检查它是否像这样工作
git diff 6e46e4f
您应该具有与该提交中相同的文件,但存在错误,然后在历史记录中恢复
。。。。或者,如果要在一次提交中撤消两次错误提交
git reset --hard 6e46e4f # to make the files how you want them
git reset b265eb4 # to get back to the last commit
git diff # should see local changes that undo everything in the last two commits
git add -A
git commit -m"undo last couple commits"
git diff 6e46e4f # the state of the files should be the commit you wanted to go back to
旁边两个
git revert b265eb43abd7704ed2560cca7c635dbd47b677b0
git revert 536d071bf99059ff8b519ae96ce6e97d92fbc7d7
您可以签出目标位置并提交它
git checkout 6e46e4ff4135b4df55866a5df9af963e3d6ff218 -- .
git commit -m 'reverted some stuff'
旁边两个
git revert b265eb43abd7704ed2560cca7c635dbd47b677b0
git revert 536d071bf99059ff8b519ae96ce6e97d92fbc7d7
您可以签出目标位置并提交它
git checkout 6e46e4ff4135b4df55866a5df9af963e3d6ff218 -- .
git commit -m 'reverted some stuff'
Git恢复提交:
撤消1提交:
$ git reset --hard HEAD~1
或
删除上次提交:
$ git push -f
这将破坏任何本地修改。
如果你有未完成的工作要做,就不要做
$ git reset --hard COMMIT
Git恢复提交:
撤消1提交:
$ git reset --hard HEAD~1
或
删除上次提交:
$ git push -f
这将破坏任何本地修改。
如果你有未完成的工作要做,就不要做
$ git reset --hard COMMIT
为什么不删除冲突,提交然后还原?为什么不删除冲突,提交然后还原?git reset-硬对answear足够git reset-硬对answear足够