git 如何在 Visual Studio 中删除未推送的传出提交?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/47114113/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to remove an unpushed outgoing commit in Visual Studio?
提问by Tony_Henrich
I accidentally pushed a staged change in a new branch in Visual Studio 2017 to my local repository. It hasn't been pushed to the remote repository. I want to get rid of it but can't find a way to do this. I rebased from local master branch to the new branch. Then I deleted the new branch. But Outgoing Commits still shows it. How to delete it or revert it?
我不小心将 Visual Studio 2017 中新分支中的分阶段更改推送到我的本地存储库。它尚未推送到远程存储库。我想摆脱它,但找不到办法做到这一点。我从本地主分支重新定位到新分支。然后我删除了新分支。但是 Outgoing Commits 仍然显示它。如何删除或恢复?
回答by jessehouwing
Open the history tab in Team Explorer from the Branches tile (right-click your branch). Then in the history right-click the commit before the one you don't want to push, choose Reset. That will move the branch back to that commit and should get rid of the extra commit you made. In order to reset before a given commit you thus have to select its parent.
从分支磁贴(右键单击您的分支)打开团队资源管理器中的历史记录选项卡。然后在历史记录中右键单击您不想推送的提交之前的提交,选择重置。这会将分支移回该提交,并且应该摆脱您所做的额外提交。为了在给定提交之前重置,您必须选择其父项。
Depending on what you want to do with the changes choose hard, which will get rid of them locally. Or choose softwhich will undo the commit but will leave your working directory with the changes in your discarded commit.
根据您想对更改做什么,选择hard,这将在本地摆脱它们。或者选择软,这将撤消提交,但会将您的工作目录与丢弃的提交中的更改一起保留。
回答by Chaos Legion
I could not find a single good answer that helped me get rid of this issue.
我找不到一个好的答案来帮助我摆脱这个问题。
Let's say the name of branch, you accidentally committed changes to, is master
. Following four simple steps proved like a world to me:
假设分支的名称,您不小心提交了更改,是master
. 以下四个简单的步骤对我来说就像一个世界:
- Go to Branches
- Choose or create any branch other than
master
- Delete local/workspace version of
master
- Switch to master from
remotes/origin
- 前往分行
- 选择或创建任何分支,而不是
master
- 删除本地/工作区版本
master
- 从切换到主
remotes/origin
回答by JB4375
Assuming you have pushed most recent changes to the server:
假设您已将最新更改推送到服务器:
- Close Visual Studio and delete your local copy of the project
- Open Visual Studio, go to Team Explorer tab, click Manage Connections. (plug)
- Click the dropdown arrow next to Manage Connections, Connect to a Project
- Select the project, confirm the local path, and click the Connect button.
- 关闭 Visual Studio 并删除项目的本地副本
- 打开 Visual Studio,转到“团队资源管理器”选项卡,单击“管理连接”。(插头)
- 单击“管理连接”、“连接到项目”旁边的下拉箭头
- 选择项目,确认本地路径,点击连接按钮。
Once you reopen the project both commits and changes should be zero.
重新打开项目后,提交和更改都应为零。
回答by Mohammad Abu Saloum
You have 2 options here to do that either to discard all your outgoing commits OR to undo specific commit ..
您在这里有 2 个选项可以这样做,要么放弃所有传出提交,要么撤消特定提交..
1- Discard all your outgoing commits:
1- 丢弃所有传出提交:
To discard all your outgoing commits For example if you have local branch named master from remote branch, You can:
丢弃所有传出提交例如,如果您有来自远程分支的名为 master 的本地分支,您可以:
1- Rename your local branch from master to anything so you can remove it. 2- Remove the renamed branch. 3- create new branch from the master
1- 将您的本地分支从 master 重命名为任何内容,以便您可以将其删除。2- 删除重命名的分支。3-从主创建新分支
So now you have a new branch without your commits ..
所以现在你有了一个没有提交的新分支..
2- Undo specific commit:To undo specific commit you have to revert the unneeded by:
2- 撤消特定提交:要撤消特定提交,您必须通过以下方式还原不需要的提交:
1- Double click on the unneeded commit. Double click on the unneeded commit2- Click on revert Click on revert
1- 双击不需要的提交。 双击不需要的提交2- 单击还原 单击还原
But FYI the reverted commit will appear in the history of your commits with the revert commit ..
但是仅供参考,还原的提交将出现在您的提交历史中,并带有还原提交..