如何放弃git本地分支更改? [英] how to discard git local branch changes?

查看:122
本文介绍了如何放弃git本地分支更改?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何丢弃git本地分支更改?
例如,具有以下版本的本地分支:A-> B-> C
现在我在版本A上,它与最新版本C有一些变化冲突。
我想放弃本地更改并拉动最新版本C。

  $ git pull 

我会遇到一些错误。并且有很多文件,所以我不需要做很多次 $ git co文件



任何更好的方法?

解决方案

如果您有未放弃的更改要放弃,请使用以下命令:

  $ git reset --hard 



<这相当于

$ $ $ $ git reset --hard HEAD

pre>

这将删除所有本地未提交的更改。如果您想从本地分支中删除一些违规提交,请尝试倒带它:

  $ git reset --hard HEAD ^#将HEAD移回一个提交

或者例如

  $ git reset --hard HEAD〜3#将头部移回3次提交

请谨慎使用这些操作,因为您无法撤消这些操作。清理完本地分支后,使用 git pull 获取最新的代码。


how to discard git local branch changes? eg, local branch with version: A->B->C Now I am on version A, and it has some changes conflict with latest version C. I want to discard local changes and pull the latest version C.

$ git pull

I will meet some error. and there are many files, so I don't need to do many times $ git co files

Is there any better way?

解决方案

If you have uncommitted changes that you want to discard, use this:

$ git reset --hard

which is equivalent to

$ git reset --hard HEAD

This removes all the local uncommitted changes. If you want to remove some offending commits from your local branch, try rewinding it:

$ git reset --hard HEAD^ #moves HEAD back by one commit

or e.g.

$ git reset --hard HEAD~3 #moves HEAD back by 3 commits

Use these with caution, as you won't be able to undo these operations. Once you're done cleaning up your local branch, use git pull to get the latest code.

这篇关于如何放弃git本地分支更改?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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