git 如何在不提交更改的情况下在 Eclipse 中切换分支
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13970596/
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
How to switch branches in eclipse without commiting changes
提问by Eddie
I've been using GIT for a couple of weeks now and trying to understand how to switch branches without commiting files. This is what I have done.
我已经使用 GIT 几个星期了,并试图了解如何在不提交文件的情况下切换分支。这就是我所做的。
- Cloned a git repository and have a local master branch.
- Created a new local branch (Branch2) which is based on a remote branch.
- Made changes to 2 files in the master branch.
- 克隆了一个 git 存储库并拥有一个本地 master 分支。
- 创建了一个基于远程分支的新本地分支 (Branch2)。
- 对 master 分支中的 2 个文件进行了更改。
What I want to do now is switch from master to Branch2. The changes I made to the master branch are for local dev purposes only and should never be committed. But when I try to do this in eclipse (i.e I double click on the local branch I try to switch to) it keeps telling me that there are uncommitted changes and I need to commit, stash or reset.
我现在想做的是从 master 切换到 Branch2。我对 master 分支所做的更改仅用于本地开发目的,不应提交。但是当我尝试在 Eclipse 中执行此操作时(即我双击我尝试切换到的本地分支),它一直告诉我有未提交的更改,我需要提交、存储或重置。
Can anyone tell me how i can make a change to a local file and have git ignore this change so that I don't get prompted with this message?
谁能告诉我如何更改本地文件并让 git 忽略此更改,以便我不会收到此消息的提示?
采纳答案by Willem D'Haeseleer
If you don't want the changes to be ever made public you should just commit them in your own feature branch and not on the master branch.
You can create a new branch, give it a name that reflects the changes, maybe prefix is with something like "experimental-" and then commit to that branch before switching to your other branch.
如果您不希望更改公开,您应该只在您自己的功能分支而不是在主分支上提交它们。
您可以创建一个新分支,给它一个反映更改的名称,也许前缀是“实验-”之类的东西,然后在切换到另一个分支之前提交到该分支。
You can use git stash to stash your changes, or use git stash to commit them directly to a new branch as mentioned by Ege Akpinar.
您可以使用 git stash 来存储您的更改,或者使用 git stash 将它们直接提交到 Ege Akpinar 提到的新分支。
回答by VonC
Note: if you need to stash a work in progress from Eclipse, Egit now supports stash:
注意:如果您需要从 Eclipse 中存储正在进行的工作,Egit 现在支持 stash:
回答by Ege Akpinar
Have a look at git stash. Stash allows you to store uncommitted changes.
看看 git stash。Stash 允许您存储未提交的更改。
Option 1
选项1
git stash
git checkout -b Branch2
Your changes will be stored in git (locally). When you want to re-apply those changes, you will do git stash pop
and it will apply those changes for you.
您的更改将存储在 git(本地)中。当您想重新应用这些更改时,您会这样做git stash pop
,它会为您应用这些更改。
Option 2
选项 2
git stash
git stash branch temporarybranch
This will take your uncommitted changes to a new branch and keep them there for you. Compared to the previous option, this allows you to keep these branches on the server by pushing this new branch.
这会将您未提交的更改带到新分支并为您保留它们。与之前的选项相比,这允许您通过推送这个新分支将这些分支保留在服务器上。
Hope it helps
希望能帮助到你