Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EGit / JGit » [JGit] How to checkout using SHA-1
[JGit] How to checkout using SHA-1 [message #714146] Tue, 09 August 2011 22:06
eclipse-relay is currently offline eclipse-relayFriend
Messages: 1
Registered: August 2011
Junior Member
I have a fairly simple use case that involves a checkout using a SHA-1 in order to change an existing working directory. My use case:

1.) Fetch/Pull changes into an existing working directory
2.) Dump a listing of all repo tags and associated SHA-1
3.) Perform a checkout in that working directory for a given SHA-1

I am able to use JGit for 1 and 2 and I get the expected results. My knowledge/use of the CheckoutCommand, however, does not appear to do anything to my working directory. Here's a quick summary of what I'm doing:

FileRepositoryBuilder builder = new FileRepositoryBuilder();
repository = builder.setGitDir(MyRepositoryFile).findGitDir().build();
Git git = new Git(repository);

//1.) - Fetch updates, Works as expected
FetchResult fetchResult;
fetchResult = git.fetch().call();

//2.) - Print out tag values, Works as expected
Collection<Ref> values = repository.getTags().values();;
for (Ref i : values) {
//print value

//3.) - Checkout a SHA-1 path, Does not Work (as expected)
CheckoutCommand checkoutCommand = git.checkout();
checkoutCommand.setName("task" +;
Ref checkoutResult =;

When I look inside the working directory (MyRepositoryFile), the contents are exactly the same as before I called the checkoutcommand. Does anyone have any thoughts or sample code for check outs using a SHA-1 as a path? All I can find is the jgit test package and that has only gotten me so far.

[Updated on: Tue, 09 August 2011 22:26]

Report message to a moderator

Previous Topic:Merge "using strategy resolve resulted in: Failed."
Next Topic:better reset
Goto Forum:

Current Time: Sat Jun 06 14:48:53 GMT 2020

Powered by FUDForum. Page generated in 0.01830 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top