"git reset --hard"行为 [英] Behavior of "git reset --hard"

查看:82
本文介绍了"git reset --hard"行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在本地主机中创建了一些提交.不久之后,我意识到我应该建立一个新的分支并将这些提交放置在那里.我很容易就能建立一个包含我所有提交的新分支.

I created a few commits in my local master. Before long I realized I should have setup a new branch and placed these commits there. I was easily able to setup a new branch which had all my commits.

我现在要解决的是如何从本地master分支中删除这些提交.

What I need to address now is how to remove these commits from my local master branch.

我以为我会运行"git reset --hard #lastHash",但我担心这种行为或在master分支上运行

I am thinking I would run "git reset --hard #lastHash" but I am worried about the behavior or running this on the master branch

由于自从我开始进行自己的提交以来,我还没有从orgin/master推送或获取任何更新,因此硬重置仅会影响我的本地历史记录吗?我担心的是,在我开始进行自己的本地提交之后,在原始/主文件上创建了一些提交

Since I have not pushed or fetched any updates from orgin/master since I began making my own commits, will the hard reset only affect my local history? My concern is there are commits on origin/master that were created after I had starting making my own local commits

推荐答案

git reset --hard <hash>仅会更改您的本地存储库,除非您使用push跟进它.

git reset --hard <hash> will only change your local repository, unless you follow it up with a push.

  1. git checkout master
  2. git reset --hard <commit hash>
  1. git checkout master
  2. git reset --hard <commit hash>

其中<commit hash>是您想要master分支的提交的哈希.这将重置当前分支头到<commit hash>.

Where <commit hash> is the hash of the commit where you want the master branch. This will reset the current branch head to <commit hash>.

这篇关于"git reset --hard"行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆