git 在 SourceTree 中重置提交
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35714762/
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
Reset commit in SourceTree
提问by Roe
I have 2 branches master
and bugfix
. my current branch is bugfix
, where I have committed my changes (not pushed), now I need to reset this commit.
我有 2 个分支master
和bugfix
. 我当前的分支是bugfix
,我已经提交了我的更改(未推送),现在我需要重置此提交。
If I do reset my commit, will it affect other commits in master
branch?
如果我确实重置了我的提交,它会影响master
分支中的其他提交吗?
Actually I want to remove this commit.
其实我想删除这个提交。
git reset --soft 734e3a0
I am using SourceTree.
我正在使用 SourceTree。
采纳答案by MUSTKEEM MANSURI
You need to run this command in source tree terminal git reset --soft HEAD~1
this command push back your commit in your sourtree. then you take latest pull and then you can commit your code.
您需要在源代码树终端中运行此命令,git reset --soft HEAD~1
此命令将您在酸树中 的提交推回。然后你获取最新的 pull 然后你可以提交你的代码。
回答by Surendra Reddy
Simply go to Log/History in source tree, select the previous commit of the commit which we you want to undo and right click and do 'Reset current branch to this commit' This will discard your committed changes(which were not pushed).
只需转到源树中的日志/历史记录,选择我们要撤消的提交的先前提交,然后右键单击并执行“将当前分支重置为此提交”这将丢弃您提交的更改(未推送)。
It won't impact anything in master branch
它不会影响主分支中的任何内容
回答by Charitha Goonewardena
If you have not pushed your code to remote you can revert your change by following below steps shown as in the image.But please BACKUP your Changes first1. Go to SourseTree terminal
2. Execute the command git reset HEAD~
Then go to file status and check.
如果您尚未将代码推送到远程,您可以按照如下图所示的步骤还原您的更改。但请先备份您的更改1. 转到 SourseTree 终端
2. 执行命令 git reset HEAD~
然后转到文件状态并检查。
回答by Chuck
I don't think doing a git reset --soft
will affect any commits. It will only affect your branch.
我认为执行 agit reset --soft
不会影响任何提交。它只会影响您的分支。
If you want to revert commit 734e3a0
then you can try using git revert
:
如果你想恢复提交,734e3a0
那么你可以尝试使用git revert
:
git revert 734e3a0
This will instruct Git to add a new commit which undoes whatever 734e3a0
was doing originally. Note that this is a good option in the event that this commit is in the middle of a branch, and it is also a good option for a branch whose history has already been made public.
这将指示 Git 添加一个新提交,该提交会撤消734e3a0
最初所做的任何事情。请注意,如果此提交位于分支的中间,这是一个不错的选择,对于历史已经公开的分支来说,这也是一个不错的选择。
回答by CodeWizard
First of all you have to ask yourself what you want to do.
首先你得问问自己你想做什么。
What is reset
is for?
什么是reset
对?
I assume you want to undo
your changes. Do do so you have several options, which you can read about in details in here:
我假设你想要undo
你的改变。这样做你有几个选项,你可以在这里阅读详细信息:
How to move HEAD back to a previous location? (Detached head)
It will explain in details what to do in each option.
它将详细解释在每个选项中要做什么。
What needs to be done?
What needs to be done?
You have to set up your HEAD to point to a new (or old) commit.
The above post will show you and will teach you what to do and will show you few options.
您必须将 HEAD 设置为指向新的(或旧的)提交。
上面的帖子将向您展示并教您做什么,并向您展示几个选项。