Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EGit / JGit » How do you add a change to the index?
How do you add a change to the index? [message #688469] Fri, 24 June 2011 18:52 Go to next message
James Moore is currently offline James MooreFriend
Messages: 3
Registered: March 2011
Junior Member
I'm a bit embarrassed to even have to ask this, but I can't even figure out the basic operation of how to add a change to the index. What's the egit equivalent of 'git add -i'?

The things I tried didn't help me; I pulled up the diff of a file, right-clicked on a change, nothing there. None of the icons on the diff page seemed to be related to adding something to the index.

What am I missing?
Re: How do you add a change to the index? [message #689692 is a reply to message #688469] Tue, 28 June 2011 07:47 Go to previous messageGo to next message
Stefan Lay is currently offline Stefan LayFriend
Messages: 342
Registered: July 2009
Senior Member
When you compare a file with the index you can edit the content of the file in the index and save the editor. You can open such an editor either from the context menu (Compare With -> Git Index) or in the Git staging view by double clicking on the entry in the table "Unstaged changes".

This is kind of a hidden feature in EGit.

Stefan
Re: How do you add a change to the index? [message #689937 is a reply to message #689692] Tue, 28 June 2011 15:59 Go to previous messageGo to next message
R Shapiro is currently offline R ShapiroFriend
Messages: 386
Registered: June 2011
Senior Member
Add to the index with the "Add" operation. You can get to that operation from the right-click menu under "Team". Or, better, customize your development perspective (Java, C++, whatever) to include the toolbar items from the "Git" command group. The '+" toolbar item is "Add". You'll also get toolbar items for Push, Fetch, Pull, Commit, Checkout, Rebase and Reset

You can also do adds as part of the "Commit" operation.

Finally, you can use the very handy "Git Staging" view to drag changes from the "Unstaged" box to the "Staged" box (or vice-versa).
Re: How do you add a change to the index? [message #691206 is a reply to message #689937] Thu, 30 June 2011 23:55 Go to previous messageGo to next message
James Moore is currently offline James MooreFriend
Messages: 3
Registered: March 2011
Junior Member
R Shapiro wrote on Tue, 28 June 2011 11:59
Add to the index with the "Add" operation. You can get to that operation from the right-click menu under "Team".

But doesn't that do the special case of "commit every change in a file"? How do I convince it to let me choose which change to commit?
R Shapiro wrote on Tue, 28 June 2011 11:59

You can also do adds as part of the "Commit" operation.

Perfect - but how? That UI is completely baffling. It gives me lists of files, not changes. How do I pick which changes I want, without grabbing every change in a file? I feel like I'm just not seeing something really basic. Double-clicking on a file just brings up a Java diff window, with no way to commit individual changes that I can see.
R Shapiro wrote on Tue, 28 June 2011 11:59

Finally, you can use the very handy "Git Staging" view to drag changes from the "Unstaged" box to the "Staged" box (or vice-versa).

How? I see how to drag entire files, but no way to drag changes.

In the vanilla git gui, there's a three-pane interface: one pane has the unstaged files with changes, another pane has the staged files with changes, and the third pane shows the changes in the selected file. That third pane is the core of the gui that I use all the time, choosing which changes to put into the index. What I'm looking for is the equivalent of that for egit, and for me at least, it's really hard to find.

[Updated on: Fri, 01 July 2011 00:31]

Report message to a moderator

Re: How do you add a change to the index? [message #691383 is a reply to message #691206] Fri, 01 July 2011 10:57 Go to previous messageGo to next message
R Shapiro is currently offline R ShapiroFriend
Messages: 386
Registered: June 2011
Senior Member
My apologies, I misread the original question. As you point out, the actions I mentioned are all per-file, not per-change. I don't know how to add individual changes in egit. When I'm at this level I use GitX (a Mac-specific application similar to to gitk). I'm new enough to Git in general that I still tend to think of version control as being about files.
Re: How do you add a change to the index? [message #693454 is a reply to message #691383] Wed, 06 July 2011 14:02 Go to previous messageGo to next message
R Shapiro is currently offline R ShapiroFriend
Messages: 386
Registered: June 2011
Senior Member
The more I think about this, the more I'm convinced that egit really needs to support adding individual changes to the index.

After all, why are we using Git rather than, say, Mercurial? The latter has a much cleaner and simpler design than the high convoluted design of Git. Trendiness aside, there are a couple of good reasons we pay the price of Git's excessive complexity.

The first advantage is that native Git is very fast. That this is the most important win is clear from the standard subtitle "Fast Version Control System" appearing on books and in web sites. Unfortunately we're already giving up some of this in the egit world by its use of jgit. I haven't measured but my subjective sense is that egit is no faster than MercurialEclipse, whereas command-line Git is certainly faster than command-line HG.

In the Eclipse context that leaves one reason for using git, and therefore egit: very fine-tuned control. And what's the perfect example of this? Per-change indexing. You might even say that the fineness of control is what justifies the index: if commits are always on whole files, you don't need an index to organize them, you just need checkboxes to indicate which files you want to include in any given commit.

Conclusion: support for per-change index control in egit is crucial.

The gui aspect of this could be handled in several ways. For instance it could be added to the right-click menu of the quick-diff markers, since those are already per-change. Combine that with automatic display of the selected file in Git Staging view and you have a simple solution that doesn't require any new widgits.


Comments ?
Re: How do you add a change to the index? [message #704339 is a reply to message #693454] Thu, 28 July 2011 14:12 Go to previous messageGo to next message
Stefan Lay is currently offline Stefan LayFriend
Messages: 342
Registered: July 2009
Senior Member
I'm not sure if both of you have read my previous comment in this thread:

"When you compare a file with the index you can edit the content of the file in the index and save the editor. You can open such an editor either from the context menu (Compare With -> Git Index) or in the Git staging view by double clicking on the entry in the table "Unstaged changes"."

This describes a first version of the feature to stage hunks: In the compare editor of eclipse you can select single changes inside one file and move them to the other side.

Do you agree on that? What else would you expect from a "per-change index control in egit"?
Re: How do you add a change to the index? [message #704543 is a reply to message #704339] Thu, 28 July 2011 19:15 Go to previous messageGo to next message
R Shapiro is currently offline R ShapiroFriend
Messages: 386
Registered: June 2011
Senior Member
I agree completely. Never occurred to to me to use Compare With in this way but it makes perfect sense now that I've tried it. Thanks for the clarification.
Re: How do you add a change to the index? [message #706488 is a reply to message #704543] Sun, 31 July 2011 11:46 Go to previous message
R Shapiro is currently offline R ShapiroFriend
Messages: 386
Registered: June 2011
Senior Member
Following up on your second question: What else would you expect from a "per-change index control in egit"?

While the Compare With approach covers the functionality with a familiar Eclipse widget, it's maybe not the most intuitive way to do this.

Another possibility comes to mind: extend QuickDiff. I don't know how straightforward it is to add new functionality to the QuickDiff right-click menu, but that I think would be a very clean way to add/remove changes. Just as you can revert a block or a line from here, this seems like very natural place to be able to add/remove a block or a line to/from the index.

Similarly, the QuickDiff decorations could be extended to show lines or blocks that have been staged: it would really be nice to see in text editors which uncommited changes are staged and which aren't.

Summary: add 'stage' and 'unstage' operations and a 'staged' decoration to left-gutter QuickDiff items.
Previous Topic:Derived files like .class files
Next Topic:File URI not working correctly
Goto Forum:
  


Current Time: Tue Mar 19 10:29:51 GMT 2024

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

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

Back to the top