Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EGit / JGit » Equivalent of `git add -A` and `git show` in jGit
Equivalent of `git add -A` and `git show` in jGit [message #1002468] Fri, 18 January 2013 16:35 Go to next message
Alireza Noori is currently offline Alireza NooriFriend
Messages: 2
Registered: January 2013
Junior Member
I'm looking for equivalent commands for `git add -A` and `git show` in jGit.
I know how to add a single file using this code:

git.add().addFilepattern(path).call();

However, I'm used to the command:

git add -A

Which basically adds all the files automatically.

-----------

Also, I want to retrieve a specific version of a file from Git repository. In git I use:

git show HEAD~1:file.txt

How can I achieve this in jGit?

Any help will be appreciated.
Re: Equivalent of `git add -A` and `git show` in jGit [message #1003255 is a reply to message #1002468] Sun, 20 January 2013 19:32 Go to previous messageGo to next message
Robin Rosenberg is currently offline Robin RosenbergFriend
Messages: 332
Registered: July 2009
Senior Member
Alireza Noori skrev 2013-01-18 17.48:
> I'm looking for equivalent commands for `git add -A` and `git show` in jGit.
> I know how to add a single file using this code:
>
> git.add().addFilepattern(path).call();
>
> However, I'm used to the command:
>
> git add -A

For this particular usage, 'jgit add .' will do.

> Which basically adds all the files automatically.
>
> -----------
>
> Also, I want to retrieve a specific version of a file from Git repository. In git I use:
>
> git show HEAD~1:file.txt

jgit show HEAD~1:README.md works in the JGit repo

-- robin
Re: Equivalent of `git add -A` and `git show` in jGit [message #1003286 is a reply to message #1003255] Sun, 20 January 2013 21:55 Go to previous messageGo to next message
Alireza Noori is currently offline Alireza NooriFriend
Messages: 2
Registered: January 2013
Junior Member
I'm sorry if I wasn't clear. I'm using the API library (the .jar file), not the command line version.
Thanks for the reply though.
Re: Equivalent of `git add -A` and `git show` in jGit [message #1003888 is a reply to message #1002468] Tue, 22 January 2013 07:40 Go to previous message
Robin Rosenberg is currently offline Robin RosenbergFriend
Messages: 332
Registered: July 2009
Senior Member
Alireza Noori skrev 2013-01-18 17.48:
> I'm looking for equivalent commands for `git add -A` and `git show` in jGit.
> I know how to add a single file using this code:
>
> git.add().addFilepattern(path).call();
>
> However, I'm used to the command:
>
> git add -A

"." will be interpreted as "all" files. But, I'd say that's a bug, at the defail
level. jgit add . will add all files in the working tree, even if you've cd'd to
a subdirectory. JGit is probably bad at considering the current directory in
general, so be careful. If you want to add everything at the top level, then "." is fine.

> Which basically adds all the files automatically.
>
> -----------
>
> Also, I want to retrieve a specific version of a file from Git repository. In git I use:
>
> git show HEAD~1:file.txt
>
> How can I achieve this in jGit?

See the org.eclipse.jgit.pgm.Show class. It uses Repository.resolve which will return the blob id, or you
could use TreeWalk.forPath(). The latter requires some more work. An example can be found in
org.eclipse.egit.ui.internal.decorators.GitDocument.

-- robin
Previous Topic:RefSpec question Git vs. Egit
Next Topic:["Solved"] Commit in submodule wants to remove and re-add all files with folder appended a
Goto Forum:
  


Current Time: Fri Apr 26 20:42:51 GMT 2024

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

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

Back to the top