1

DESIRED

I am a sole developer (and a beginner). I have a master branch only at the moment. Within it, I have some commits that are really different versions with different types of implementations. So, I want to make them into new branches. But I also have some functionality in the master branch that I want to merge down to these new branches. These functionality is minor and I would like to see and pick the changes precisely.

TRIED

In Egit, if I make a new branch the master files are deleted locally. So, I do not understand how I can compare versions. Can I have several branches available locally? Is it desirable? How?

If I ask to merge my master into my new branch, Egit does a fast-forward showing no conflicts or comparisons, not what I want.

REQUEST

What would be a good process to achieve my desired outcome? I am happy to mix Egit with GitBash if necessary (presuming they can mix with no problems).

BACKGROUND

A lot of similar discussion (here and here, for example) or relevant tutorials (e.g., here) but no precise match.

Thanks!

Community
  • 1
  • 1
SR98115
  • 45
  • 6

1 Answers1

1

What you need is a facility called cherry-picking.

If you have Git installed:

  1. create a branch
  2. Use the gitk --all command which shows a nice GUI about the commits of all branches you have.
  3. You can easily select the required commits and simply right-click on it and select "Cherry-pick this commit".

That's all.

rlegendi
  • 10,466
  • 3
  • 38
  • 50
  • Thanks. What I need to do is to pick changes from several commits, actually. So, I need to have the changes displayed side by side and integrated semi-manually. Maybe I shall just have to do it by hand... But I was hoping to hear what the proper way could be... – SR98115 Sep 23 '12 at 01:03
  • Hm, ain't sure if I understand your needs correctly, but [here's a screenshot about gitk](http://orestis.gr/static/upload/blog_images/2009/06/17/gitk.png): it does display changes side by side. It does the cherry-pick automatically, you just have to select the required commits and it merges it to the current branch. You can also fully automatize the task by running `git-cherry-pick` by hand, but you'll need the commit SHAs. HTH. – rlegendi Sep 23 '12 at 11:53
  • I am not very sure about my final needs myself, as a beginner. I see how gitk is very useful, so - thanks again. A couple of questions: 1) once I have displayed the differences in gitk, how do I merge or manually transfer source code changes if they do not coincide with commits? 2) if I operate using gitk, gitgui or gitbash, will eclipse/egit be able to keep up? e.g., what is checked out, merged, etc...? – SR98115 Sep 23 '12 at 16:53
  • 1
    Oh, so you want to merge in diffs, but not whole commits? Well, it can be done but it's far from trivial, I wouldn't suggest that: you have to rewrite the history and [http://git-scm.com/book/en/Git-Tools-Rewriting-History](split commits). 2) EGit can keep up, just don't forget to refresh the project (F5), older versions of Eclipse might need it. – rlegendi Sep 23 '12 at 17:07
  • I see. Thanks again. This conveniently points to further learning and indicates what is expected. Very useful. Till next time... – SR98115 Sep 24 '12 at 10:05