EGit Iteractive Adding

So what is “interactive adding” in git? Imagine situation when you change two or three lines in file (this could be also two or three blocks/methods), then you realize that you will want to commit those changes in two (three or more) separate commits.

Here is Al Blue’s description how interactive adding works in native git: Git Tip of the Week: Interactive Adding

What about EGit? Honestly this is currently supported … but it isn’t really straight forward to access. You need to select a file then choose from context menu Team > Compare With > Git Index and then you can easily move changes around, finally when you are happy with both versions (left is working tree and right is one that will be staged/added to index) just save compare editor contents. Version from right hand side will be added to index as it is in this editor.

OK, so now you can easily stage and unstage partial changes … maybe you would also like to partial replace staged changes by version in HEAD? Currently in version 1.1 you can compare version from git index with HEAD version using context menu Team > Compare With > Git Index with HEAD, but you cannot overwrite anything … yet, because (hopefully) in 1.2 such option will be available. Here is patch that adds this functionality (to be honest this is a side effect…).

And what about (my favorite) Synchronize View? Unfortunately EGit 1.1 don’t allow to move any changes in compare editors launched from Synchronize View … but with change mentioned above and with this one both features would be available from Git Commits model (before it was named as Git Change Set model)

Here is a short screen cast that shows how this work:

 

8 Comments EGit Iteractive Adding

  1. Pingback: Dariusz Luksza: EGit Iteractive Adding

  2. Carsten

    There is one thing that escapes me: it’s good practice to perform fine-grained commits with individual commit messages (which is where interactive adding helps!).

    OTOH, Gerrit forces you to join all commits together into one big “blob commit”.

    Reply
  3. Dariusz Łuksza

    @Carsten
    Working with Gerrit is little bit tricky. You (and yours team) need to find theirs own patch-size, because if you post very small patches that connects into huge change-set-chain you’ll end up with rebase/cherry-pick hell. On the other hand working with huge patches review process can take ages …

    Reply
  4. Tomasz

    Cool! The video quality could a little bit better, but for the feature itself: great work!

    Reply
  5. Sol

    Hey Darius, two quick questions:
    – Do you know if there is any ETA for 1.2 ? Also
    – Also, it is possible to add both patches to an EGIT 1.1 version or do I have to wait? The stage hunk\line part for me is essential and having that ability is one of the reasons I’m still not fully on EGIT, but using EGIT + GIT Gui

    Thanks

    Sol

    Reply
  6. Paulo Almeida

    Hi,

    I can stage partial changes using this method, but can I commit them in EGit? When I tried, I had to select the file, and all the changes in the file got committed. Is there a way to do this without going to the command line? My version of EGit is 2.2.0.

    Reply
  7. Paulo Almeida

    Nevermind my previous comment. For anyone else looking for this, you can commit partially staged changes in the Staging View (Window -> Show View).

    Anyway, thanks for the post, it showed me that this was possible in the first place.

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *