git:切换分支并忽略没有提交的任何更改 [英] git: Switch branch and ignore any changes without committing

查看:1309
本文介绍了git:切换分支并忽略没有提交的任何更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究一个git分支,并准备提交我的更改,所以我提交了一个有用的提交消息。然后我心不在焉地对那些不值得保留的代码做了小小的修改。我现在想更改分支,但git给了我,


错误:您对X进行了本地更改;无法切换分支。


我认为我可以在不提交的情况下更改分支。如果是这样,我该如何设置?如果不是,我该如何解决这个问题?我想在不提交的情况下忽略细微变化,只是改变分支。

解决方案

你需要一个干净的状态来改变分支。只有在不影响'脏文件'的情况下才允许分支结账(如 Charles Bailey

否则,您应该:


  • 隐藏您当前的更改或
  • < a href =https://git-scm.com/docs/git-reset =noreferrer> reset --hard HEAD (if你不介意丢失这些微小的变化)或
  • checkout -f (当切换分支时,即使索引或工作树不同于HEAD也是如此,用于丢弃本地更改。)


I was working on a git branch and was ready to commit my changes, so I made a commit with a useful commit message. I then absentmindedly made minor changes to the code that are not worth keeping. I now want to change branches, but git gives me,

error: You have local changes to "X"; cannot switch branches.

I thought that I could change branches without committing. If so, how can I set this up? If not, how do I get out of this problem? I want to ignore the minor changes without committing and just change branches.

解决方案

You need a clean state to change branches. The branch checkout will only be allowed if it does not affect the 'dirty files' (as Charles Bailey remarks in the comments).

Otherwise, you should either:

  • stash your current change or
  • reset --hard HEAD (if you do not mind losing those minor changes) or
  • checkout -f (When switching branches, proceed even if the index or the working tree differs from HEAD. This is used to throw away local changes. )

这篇关于git:切换分支并忽略没有提交的任何更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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