Revert modifications from a git project in Eclipse IDE

Something that I’ve missed when I switch from SVN to git was subeclipse:(

I’m using eGit, but it lacks support for doing a simple task like reverting modifications from a specific file.

eGit without reverting
eGit without reverting

Even though I’m getting use to those simple command line scripts a simple thing like reverting modifications from a specific file is kind of tedious, and this is something that I could handle in the IDE.

To simplify this procedure I’ve created a simple bash script (revert.sh):

#!/bin/bash
# @author Daniel Botelho <botelho.daniel@gmail.com>
# @date 2010-05-19
workspace_loc=$1
project_name=$2
selected_resource_path=$3
git=/usr/bin/git
cd $workspace_loc/$project_name
#echo $git status

#$git status

length=”${#project_name}”+2;
echo $git checkout ${selected_resource_path:length}
$git checkout ${selected_resource_path:length}
echo “completed.”

Then I’ve created a new External Tool Configuration to call this simple script (Run>External Tools> External Tools Configurations…>)

new_ext

Screenshot-External Tools ConfigurationsHere you should change your “Location” to the location where you have your “revert.sh” script.

Ok, and it’s done! :)

Now I can choose the file that I want to revert and click on “Run revert modifications (git)” right from the eclipse IDE.

run