Is there a way to retrieve eclipse executed git commands? - eclipse

I'm a regular git user, and I'm building some shortcuts in eclipse to activate some EGit functions.
I'm a bit wary of what is EGit doing (especially the synchronize workspace operations), and I was wondering if I could make EGit show what git commands it was using.
Do you know of an option to make it log to the console, or generally, how to find out which commands got executed?

EGit does not use the git executables. It reproduces, with the help of JGit, what the executables would do.
Git executables store the versioning state of a project in a number of files under the .git folder (branches, refs, commit objects, tags and so on).
EGit and JGit do the same.
For example:
A commit with git executables:
git commit -m "My commit message"
Would be executed in Java through EGit with CommitOperation.commit(), which uses JGit's CommitCommand.call(), which builds and inserts a commit object, which are representend through files.
There is no clear mapping between EGit's UI operations and their meaning as regular git commands, at least not to my knowledge.
One can go through (EGit, JGit, git)'s code and look for what is happening under the hood, though.
EDIT: a pgm package in JGit provides the inverse mapping: "Command-line interface Git commands implemented using JGit ("pgm" stands for program)"
EDIT: A not-merged Eclipse patch exists for logging what Egit does under the hood: https://git.eclipse.org/r/#/c/103342/

Please go to .git folder of your project. There will be a log folder like in my case (D:\Repo\GIT.git\logs)
all git command executed by eclipse are logged in respective branch file.
a sample of log is
0000000000000000000000000000000000000000 27f2e02544d389eb2412c1d467cc99f1786cd662 fanishshukla 1409137288 +0530 commit (initial): First Draft for Jboss
27f2e02544d389eb2412c1d467cc99f1786cd662 6d5634200cfdf6adf7c00ae70004326d2741e3a2 fanishshukla 1409557422 +0530 commit: fast response
6d5634200cfdf6adf7c00ae70004326d2741e3a2 32dbcfa55452b1a89861f422cfc7f90d26435d8c fanishshukla 1409557443 +0530 commit: fast response

What I found here:
There's a bug regarding this requirement:
Bug 349551 - Log EGit activities into a console
https://bugs.eclipse.org/bugs/show_bug.cgi?id=349551

How about git reflog to view command history of git

Related

Changing the git branch on eclipse

This is the first time I do this.
I imported a git project in eclipse.
Then I used the shell to create another branch and checkout to the new branch.
Is refreshing the imported project in Eclipse enough to tell Eclipse that we are working on the new created branch?
thanks
Right-click your project and select Team → Branch to create new branches or to switch between existing branches. You can also switch branches in the History view.
Actually, I don't think you even need to refresh the project. That is, assuming you have 'eGit' installed and your projects are already configure as git projects (they should be, because in most cases, egit does that automatically).
Whenever you run git commands on the shell (outside eclipse) egit will automatically refresh projects for you and update their status when you switch back to Eclipse.
If you are not using egit then yes, you have to refresh the projects manually, but that is all you'd have to do since running the 'git checkout my-branch' command in the shell already changed the files on disk to be those from 'my-branch'.
Actually when you are working with eclipse, eGit is a very cool tool integrated inside eclipse, which lets you do all git stuff, like
git checkout to a new branch
git create new branch
git stash
even view your unstaged changes(select files and avoid complexities caused by git add .)
and finally commit.
Read here to know more. Eclipse Egit user guide
So you get to do all version repository stuff at one place as you code.
So to answer your question, yes as you checkout a new branch even in a shell/command prompt your changes will be reflected in eclipse.

Will installing Egit interfere with existing Git installation?

I have been working with Git from the command-line for a few weeks. I am now on a project that uses Eclipse as the IDE and EGit for the Git plugin. I am worried that by installing EGit I'm going to destroy any Git configs in my existing projects (that I've been maintaining/coding directly from a terminal).
If EGit could interfere, how so (and how can I avoid this)? If not, why?
No, it doesnt interfere. EGit only works within Eclipse and is independent from a command line Git installation. Regarding the configuration EGit of course reads your existing gitconfig. But if you use a recent Git version on the command line, there shouldn't be any differences in the config.
In fact you can keep using Git on the command line for committing, pushing etc. It doesn't matter if the project is configured for EGit in Eclipse.

Git, SVN and Eclipse workflow

I am trying to adopt the following workflow:
git svn clone a svn repository through command line (egit doesn't support git-svn)
Open the project in eclipse with egit since I rather use egit to branch, merge, commit etc...
When i'm ready commit the changes back, I use use git svn dcommit to commit back to svn
I am having trouble with step number 2, don't understand how to import a git project, eclipse tells me i can't import it to use the same directory it's currently in because another project with the same name is already there. this is confusing.
Anyone knows how to do this ?
Also would like to hear other workflow examples that uses egit and git svn. I am aware that it is better to do it all through command line, however, I am trying to ease the move to git for fellow developers in my team, who are not used to command line interface etc...
I've worked briefly with the egit plugin (I actually recently stopped using it and just use msysgit as my Git guiclient and run it separately from Eclipse). I find Eclipse very busy as is and adding this plugin slows it down (for me at least).
What I did when setting up an already cloned project in Eclipse:
In Eclipse. File -> Import -> Existing Project into Workspace
Select root directory of project. Do NOT check copy projects into workspace. Click finish.
After project has been imported. Right click on project, go to Team -> Share Project
Select Git as a repo type, click next
Check use or create repo in parent folder of project. Since you already cloned the project it will be tracked with git. When you check this option it will show the project, the path, and the repo (.git).
Click finish and you will be all set.
I think you'd better use SubGit instead of git-svn.
SubGit works on a server side. It synchronizes all the modification between Subversion and Git repositories automatically on every incoming modification from either side.
From the client perspective SubGit enabled repository is a usual Git repository, so you may pull from and push to it. Please refer to SubGit documentation or SubGit vs. git-svn comparison for more details.

EGit - Switching branches doesn't remove empty directories/packages

I'm using EGIT to manage my GIT repository, which seems to work well so far. However, when I switch from one branch to another the files are correctly switched, however empty directories and packages that exist in one branch but not the other are left over.
I understand that GIT is based on the actual files and not the directories, however this is not ideal as my one branch was a large refactoring and therefore contains many packages that the master branch does not have.
From my research there appears to be a GIT command git clean -d that should cleanup the directories. Does EGIT support this? Or is there a way to execute this command when switching the branch with EGIT?
That looks like bug 345585: "EGit does not prune empty folders when switching branches".
It is still opened, so for now, the git clean -d is your best option (but outside of Eclipse, in a shell session).
Update June 2013, for Egit 3.0 Kepler:
A clean action has been added to the repositories view now.

Git-svn and Eclipse?

Is there a plugin for Eclipse for git-svn? I'm looking for a way to handle the SVN repo with Git (for fast branch switching etc.)
It does not look like there is a Git plugin for Eclipse that supports git-svn yet.
EGit appears to be the most active and popular Git plugin for Eclipse at the moment and it does not support git-svn, but there isn't anything stopping you from using EGit with Eclipse and interacting with git-svn via command line (or via tortoise git for example).
Eclipse bug 315264 is the EGit bug for supporting git-svn, and it looks like something that the maintainers of EGit are willing implement, but they have other priorities atm. So make sure you vote for this bug if you want the feature.
EGit is the only Git plugin for Eclipse at the moment. It doesn't support git-svn. But there is a way to make EGit work with your Subversion repository and this approach works well with any other Git client.
SubGit is the server-side solution that enables Git access to your Subversion repositories as well as Subversion access to Git repositories. You may refer to SubGit documenation for more details, but in general they are quite straightforward:
$ subgit configure --layout auto $SVN_URL $GIT_REPO
# Adjust $GIT_REPO/subgit/config
# to specify your branches, tags and other settings
# Adjust $GIT_REPO/subgit/authors.txt
# to introduce svn author names to their git counterparts
# Adjust $GIT_REPO/subgit/passwd
# in case you have no SVN credentials cached on your machine
$ subgit install $GIT_REPO
$ ... translating ... a little git is gonna born right here ...
$ TRANSLATION SUCCESSFUL
After that:
You have Git repository at $GIT_REPO synchronized with SVN repository at $SVN_URL; this sync is reliably bi-directional, i.e. both SVN and Git repositories remain writable and SubGit takes care of changes from both sides.
SubGit has installed hooks into $GIT_REPO/hooks directory which are triggered on every git push to that repository.
SubGit polls SVN repository in order to fetch new revisions.
Please note that your teammates may use the same mirror for sending their changes to Subversion repository. In this case you should setup Git server, fortunately, SubGit supports virtually every Git server available at the moment:
Apache HTTP server with git-http-backend, GitLab, Gitosis, Gitolite: supported out of the box;
Atlassian Bitbucket Server: in this case you can use SVN Mirror add-on which is built on SubGit engine;
Gerrit: you'd need to install SubGit plugin for Gerrit in this case;
Disclaimer: I'm SubGit developer; SubGit is commercial software with free options for small teams, Open Source and Academic projects.
Although this question is 4 years old, I thought I would share my recently found workaround:
Open "External Tools Configurations" (right next to "Run
Configurations") and create a new "Program" configuration.
For the working directory, choose your project from the workspace.
Enter svn dcommit into the arguments textfield.
Duplicate the configuration and replace svn dcommit by svn rebase.
Now you can launch git svn dcommit and git svn rebase with two clicks.