Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EGit / JGit » Possible to do the same as "git checkout master -- ." command line?
Possible to do the same as "git checkout master -- ." command line? [message #1780472] Tue, 23 January 2018 01:30 Go to next message
Jerry Shea is currently offline Jerry SheaFriend
Messages: 2
Registered: January 2018
Junior Member
Hi,

am hoping there is a way to do a checkout -- (overwrite local changes) from another branch. This is a very useful command line which can be used to revert your current branch to the same state as master.

The code I have tried looks like this:
// Starting on master, this checks out my branch
final CheckoutCommand checkoutCommand = git.checkout().
setCreateBranch(true).
setName(branch).
setUpstreamMode(CreateBranchCommand.SetupUpstreamMode.TRACK).
setStartPoint("remotes/origin/" + branch);
// this works fine
final Ref result = checkoutCommand.call();
Assert.notNull(result);

// I have tried this to "git checkout master -- ."
final CheckoutCommand checkoutCommand = git.checkout().
setCreateBranch(true).
setName(branch). // "master" gives same result
setUpstreamMode(CreateBranchCommand.SetupUpstreamMode.TRACK).
setStartPoint("master"); // "remotes/origin/master" gives same result
final Ref result = checkoutCommand.call();
// but result is null


I can't see a way to tell checkout to overwrite local changes ("--") or to get from master.

Any help gratefully received!!

Thanks, Jerry
Re: Possible to do the same as "git checkout master -- ." command line? [message #1780543 is a reply to message #1780472] Tue, 23 January 2018 19:49 Go to previous messageGo to next message
Matthias Sohn is currently offline Matthias SohnFriend
Messages: 1268
Registered: July 2009
Senior Member
try to add a call to setAllPaths(true) [1]

[1] http://download.eclipse.org/jgit/site/4.10.0.201712302008-r/apidocs/index.html
Re: Possible to do the same as "git checkout master -- ." command line? [message #1780830 is a reply to message #1780543] Mon, 29 January 2018 04:19 Go to previous messageGo to next message
Jerry Shea is currently offline Jerry SheaFriend
Messages: 2
Registered: January 2018
Junior Member
Thanks, but I'm afraid when I change my code to
final CheckoutCommand checkoutCommand = git.checkout().
setCreateBranch(false).
setAllPaths(true).
setName(branch). // "master" gives same result
setUpstreamMode(CreateBranchCommand.SetupUpstreamMode.TRACK).
setStartPoint("master"); // "remotes/origin/master" gives same result
final Ref result = checkoutCommand.call();


Then I get

org.eclipse.jgit.api.errors.JGitInternalException: Cannot lock xxxxx/.git/index. Ensure that no other process has an open file handle on the lock file xxxxx/.git/index.lock, then you may delete the lock file and retry.
at org.eclipse.jgit.api.CheckoutCommand.call(CheckoutCommand.java:331)
at software.chronicle.release.fs.GitWrapperImpl.lambda$checkoutBranch$1(GitWrapperImpl.java:71)
at software.chronicle.release.fs.GitWrapperImpl.gitAction(GitWrapperImpl.java:144)
at software.chronicle.release.fs.GitWrapperImpl.checkoutBranch(GitWrapperImpl.java:59)
Re: Possible to do the same as "git checkout master -- ." command line? [message #1781500 is a reply to message #1780830] Wed, 07 February 2018 23:19 Go to previous message
Matthias Sohn is currently offline Matthias SohnFriend
Messages: 1268
Registered: July 2009
Senior Member
maybe your application crashed earlier and left a stale file lock in the file system ?
Otherwise use OS tools to find out if there is another process having an open file handle on that file.
Previous Topic:how to extend egit to pre-define commit message
Next Topic:how update bare repository using jgit?
Goto Forum:
  


Current Time: Tue Apr 16 10:47:04 GMT 2024

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

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

Back to the top