24 January 2017

Pushing Specific Commit in Eclipse Git

This post describes the real-world scenario, then offers the steps to solve the issue at the bottom. If you are in a hurry, jump to the end of the post to see the steps in Eclipse, without my self-indulgent story-telling!

A few months ago, my team switched from the ancient Visual SourceSafe to Git. While we tried to minimize the process impact, the change-over was such a big shift in thinking that, months later, I still field several questions a week.

Here is a recent trouble-shooting sample: a colleague got caught in mid-task with an urgent fix, and mucked up some commits in her local repository. Her question: how can only the fix-commit be pushed.

Email excerpt:
Hey Steve!
Okay - so I have 2 files that I need to push to repository X for a high priority fix for tomorrow.

I have a 3rd file that I was in the middle of changing when I had to interrupt to get the high priority one fixed and in.  It is currently in a state of flux and full of errors.

But when I went to do a pull so that I could push the 2 needed files, I was forced to commit my changes to the 3rd file or lose them.  I didn’t want to lose them, so I committed them.

But I need to push the 2 good files and I don’t want to break things by pushing the 3rd not-yet-ready file.

What do I do?????
(end email excerpt)

18 January 2017

Faster Git History View in Eclipse

Actually, 2 tips about Git History view in Eclipse today:

(1) Faster loading of History view in Eclipse
Sometimes in Eclipse, viewing the History of a file, folder, repository or branch can take several seconds to load. Git promises faster access to the History of source changes because they are local, and this is generally true. But when there are thousands of files and many years of history, including occasional refactoring and restructuring, the History view can lose some of that speed.

One simple setting change made our History views in Eclipse faster:
In Eclipse, select Window -> Preferences.
In the tree-view of categories, navigate to Team -> Git -> History
Uncheck the preference for “Follow Renames”
Click OK.

This made a big speed improvement in our History view’s load time. 
But it comes with a cost:

4 January 2017

Abort a Git Merge or Cherry-Pick

Recently a colleague of mine used the Git Cherry-pick feature to bring one of their commits from one branch of our repository to another. They hit a somewhat complex merge conflict and, in trying to resolve all of the conflicts in the file, they got confused about what needed to be done.

They came to see me with the question: can they cancel their cherry-pick and partial merge, and start over?

The answer is Yes: it is possible to abort a merge or a cherry-pick Git operation.

Most of the time it is not needed; with a little work and human intelligence, the merge conflicts can be resolved without too much trouble. But sometimes, in cases like my colleague faced, a more complex merge winds up confusing the developer, and they want to go back and start over.

If you use git from the command-line, it’s as simple as:
git cherry-pick --abort
or
git reset --merge

On my team, about a quarter of us use Git from the command line, but most - like my colleague in this story - prefer to use the Eclipse Git plug-in. Unfortunately, the user guide for the Eclipse Git plugin does not specifically mention aborting a Cherry-pick operation. 

But a Cherry-pick is a particular kind of Merge. And a Merge can be aborted in Eclipse Git by doing a Hard Reset of the branch. 


As shown in the attached image, right-click on the branch and select "Reset..." Then choose Hard reset in the popup dialog:

A little more information is available in the EGit User Guide:
and