Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/github/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Git 如何在不删除更改的情况下删除远程提交_Git_Github_Gitlab - Fatal编程技术网

Git 如何在不删除更改的情况下删除远程提交

Git 如何在不删除更改的情况下删除远程提交,git,github,gitlab,Git,Github,Gitlab,我不小心添加了一个用户名错误的提交,并将其推到了远程。现在我想删除这个特定的提交,但我想保留更改 有办法做到这一点吗?我尝试了git reset,但这意味着我将丢失更改。有没有办法压缩提交?使用git可以将以前的提交压缩为一个提交。我建议您再添加一个提交。并使用您添加的最后一次提交挤压错误用户的提交 假设您有来自git日志的以下提交--oneline-2 xf71a11-上次提交 1a9ddqw-使用错误的用户完成提交 要挤压使用错误用户完成的提交,应使用git命令: git rebase

我不小心添加了一个用户名错误的提交,并将其推到了远程。现在我想删除这个特定的提交,但我想保留更改


有办法做到这一点吗?我尝试了git reset,但这意味着我将丢失更改。有没有办法压缩提交?

使用git可以将以前的提交压缩为一个提交。我建议您再添加一个提交。并使用您添加的最后一次提交挤压错误用户的提交

假设您有来自
git日志的以下提交--oneline-2

  • xf71a11-上次提交
  • 1a9ddqw-使用错误的用户完成提交
要挤压使用错误用户完成的提交,应使用git命令:

git rebase -i HEAD~2
这将打开编辑器,其中包含以下内容:

pick xf71a11 - last commit

pick 1a9ddqw - commit done with the wrong user
更改如下:

pick xf71a11 - last commit

squash 1a9ddqw - commit done with the wrong user

非常重要:记住,此操作会修改提交的历史记录。这可能会导致在更改之前提取提交历史记录的开发人员之间的git历史记录不一致。

感谢您的回复,但这不起作用,因为我在两者之间合并了提交。我尝试这个时出错了。还有其他想法吗?