Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to switch branches in eclipse without commiting changes

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.

  1. Cloned a git repository and have a local master branch.
  2. Created a new local branch (Branch2) which is based on a remote branch.
  3. Made changes to 2 files in the master branch.

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.

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?

like image 846
Eddie Avatar asked Dec 20 '12 10:12

Eddie


People also ask

Can you switch branches without committing?

when you switch to a branch without committing changes in the old branch, git tries to merge the changes to the files in the new branch. If merging is done without any conflict, swithing branches will be successful and you can see the changes in the new branch.

How do I switch between branches in eclipse?

To create a new branch in your repository, right click a shared project and navigate to Team => Switch to => New Branch… from the context menu. Select the branch you want to create a new branch from, hit New branch and enter a name for the new branch. The new branch should appear in the branch selection window.

Does switching branches change files?

When you switch branches, files that are not tracked by Git will remain untouched. Since Git does not know about new_file. dat , it will not just delete it.


1 Answers

Note: if you need to stash a work in progress from Eclipse, Egit now supports stash:

stash in EGit

like image 79
VonC Avatar answered Oct 04 '22 19:10

VonC