gpt4 book ai didi

How do I replicate the Get comand used by IntelliJ Idea to go back to earlier git commit but keep ion master branch not go in detached state(如何复制IntelliJ Idea使用的GET命令以返回到较早的GIT提交,但保持ION主分支不处于分离状态)

转载 作者:bug小助手 更新时间:2023-10-28 13:58:15 24 4
gpt4 key购买 nike



I use git in a simple way that works usually well for me. I am sole developer and I just use a single master branch, working on one fix/feature at a time I commit regularly (a few times a day) to my master branch and once a day I push back to the remote master branch hosted on bitbucket.

我以一种简单的方式使用git,通常对我来说效果很好。我是唯一的开发人员,我只使用一个master分支,每次只处理一个修复/功能,我定期(每天几次)提交到我的master分支,每天一次推回到bitbucket上的远程master分支。


Occasionally I want to go back a few steps and using my IDE (Intelli Jetbrains) I can use Get to go back to a previous commit and then in carry on and commit further changes to master without problems.

有时我想返回几个步骤,并使用我的IDE(Inteli JetBrains),我可以使用GET返回到上一次提交,然后继续并将进一步的更改提交给Master,而不会出现问题。


But I dont know what Get does under the covers as this does not seem to be a Git command.

但我不知道Get在被子里做了什么,因为这似乎不是Git的命令。


Can someone tell me the correct set of commands to replicate this from command line. So that I can go back to earlier commit whilst staying on the master branch and then a subsequent commit will mean the codebase is same as this earlier commit plus changes in the commit.

谁能告诉我从命令行复制它的正确命令集是什么?这样我就可以在停留在主分支上的同时返回到较早的提交,然后随后的提交将意味着代码库与这个较早的提交相同,加上提交中的更改。


更多回答

Could you add a screenshot of the actual Get command/button that you're using (I couldn't find it)? WIth that information, it should be possible to find out what exactly happens behind the scenes by checking the source code.

你能添加一个你正在使用的实际GET命令/按钮的屏幕截图(我找不到它)吗?有了这些信息,应该可以通过检查源代码来找出幕后到底发生了什么。

优秀答案推荐

The detached state is caused by your having said git checkout or git switch with the SHA of the commit you want to go back to. Instead, use git reset --hard. You could say simply

分离状态是由于您使用要返回的提交的SHA设置了git签出或git开关而导致的。取而代之的是Git Reset--Hard。你可以简单地说


get reset --hard <SHA>

Alternatively, you can do this by counting steps:

或者,您可以通过计算步数来执行此操作:


git reset --hard @~<n>

where <n> is the number of steps (commits) back you want to go. For example, if you have

其中 是要后退的步数(提交)。例如,如果您有


A -- B -- C -- D <- master

then

然后


git reset --hard @~2

will give you

会给你带来


A -- B <- master

and now you are ready to make new commits on master starting after B.

现在,您已准备好从B之后开始对主服务器进行新的提交。


Observe that this throws away commits C and D. If you think there might be some reason for preserving them, make a branch before the hard reset, like this:

注意到这会丢弃提交的C和D。如果您认为可能有某些原因需要保留它们,请在硬重置之前创建一个分支,如下所示:


git branch maybe-useful-so-keep-it

(or whatever branch name you'd like to use here).

(或您想在此处使用的任何分支机构名称)。




How do I go back to B without losing C and D, Essentially, I think I want a new commit after D called E which is identical code wise to B



the way to do it without removing the other commits it to use git reset --soft <sha> this will reset the HEAD to commit B, then you can make other commits and and any changes from C and D will be included in the next commit you perform.

在不删除另一个的情况下执行此操作的方法是将其提交到使用Git Reset--soft 这会将Head重置为Commit B,然后您可以进行其他提交,来自C和D的任何更改都将包含在您执行的下一次提交中。


https://git-scm.com/docs/git-reset#Documentation/git-reset.txt---soft

Https://git-scm.com/docs/git-reset#Documentation/git-reset.txt---soft


you can also view the console tab in your IDE to view the commands executed by the git client.
https://www.jetbrains.com/help/idea/version-control-tool-window-console-tab.html

您还可以查看IDE中的控制台选项卡,以查看GIT客户端执行的命令。Https://www.jetbrains.com/help/idea/version-control-tool-window-console-tab.html


更多回答

@paul-taylor did this work for you?

@保罗-泰勒为你做了这件事?

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com