我无意间把错误的档案 写错给Git 基特,但还没有将承诺推进到服务器上。

我如何解除那些承诺?当地当地仓库?


当前回答

使用使用git revert <commit-id>.

要拿到身份证明,请使用git log.

其他回答

删除已被推到 Github 的错误行为

git push origin +(previous good commit id):(branch name)

请指定您想要在 Github 重置的最后一个好承诺代号 。

例如,如果最近的承诺 ID 错误, 请用分支名称在 Git 命令上方指定前一个承诺 ID 。

您可以使用git log

尝试此选项, 硬重置到未添加文件的上一个任务, 然后 :

git reset --hard <commit_hash>

确保您有备份的更改, 以防万一, 因为它是一个困难的重置, 这意味着它们会丢失( 除非您更早隐藏) 。

第一运行 :

git reflog

这将显示您在存储库中实施的所有可能的动作, 例如, 承诺、 合并、 调用等 。

那么,请:

git reset --hard ActionIdFromRefLog

类型类型类型git log并发现最后的散列代码,然后输入:

git reset <the previous co>

使用什么,reset --softreset --hard?

@Kyralessa的回答:

如果您不确定该使用什么--soft(我用这个公约来纪念它)s. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

为什么?

如果您选择了--hard你会犯错,你会犯错输 输之前没有的更改。如果您选择--soft犯错后,您也可以得出相同的结果。--hard通过应用附加命令

git reset HEAD file.html
git checkout -- file.html

完整示例

echo "some changes..." > file.html
git add file.html
git commit -m "wrong commit"

# I need to reset
git reset --hard HEAD~1 (cancel changes)
# OR
git reset --soft HEAD~1 # Back to staging
git reset HEAD file.html # back to working directory
git checkout -- file.html # cancel changes

感谢@Kyralessa。