How to commit changes inside a submodule in Eclipse's eGit? - eclipse

So Eclipse's git plugin - eGit - has been supporting submodules for a while now (they added support in 1.3 release on February 15, 2012, so over a year now). I've just started to use them. I am able to add a submodule without a problem, I can create and checkout a branch inside the submodule for my local patches. I can also create a commit in the submodule.
But how do I update master repository with the pointer to the new commit? When I choose "Update submodule" it rather reverts me back to the original commit that was checked out upon adding the submodule (which isn't surprising when you think what git submodule update does). When I hit "Sync submodule" it doesn't appear to do anything at all.
So is there a way to make the master repo aware of the new commits in the submodule using eGit? I know perfectly well how to do that from the command line, but still I am trying to find out if that is possible from eGit.

Once you have modified a submodule, the Egit status done on the parent repo level should detect that this submodule has changed.
(git status, -- or gitsubmodule status implemented in JGit -- would detect any change in the submodules)
You should be able to commit, in the parent repo, even if no other files (of the parent repo) have changed, because of the "modified" state of the submodule.
That commit, recording a new SHA1 in the .gitmodules file and a special entry in the working tree, will record the new state of that submodule in the parent repo.

Related

Egit: You are in detached head state. This means that you don't have a local branch checked out

I recently created a project on Eclipse. I set up a git repository on the project. Pushed the code to a new repository on GitLab.
I checked out (Import->Project from Git) the project to another laptop, made updates, committed it as another author and pushed it back to repository (2nd commit /revision). I only removed the target runtimes from the project as the changes.
I went to my 1st laptop and wanted to try update / pull my code. I right-clicked on the repository from the Git Repository view -> Remote -> Fetch. I entered the path to the repository and etc and fetched the repository. But, my project still has the old code having the target runtime. I know I only 'fetched' the repository, not 'pulled' maybe.
So I was confused, the code was not updated. If I am not mistaken, I right-clicked the repository again, clicked on 'Check Out'. This was the result :
After 'Checkin Out', the target runtimes on my project were removed, updated like from the 2nd commit. But there are now 2 branches and 2 refs. I don't what state my local repository is in now. And/but the local master branch was still in 'initial commit', isn't it confusing?.. My code has been updated..
I only read a bit of the git manual online, and I haven't yet be able to wrap my head around concepts like refs.
I could just delete the project and Import->Project from Git, right?
But if I can I would like to know what happened to my project (local repository) and how to fix this?
Thx
I'm not familiar with egit and its menus. But I try to answer your question with git commands which you can run in the console. And I think you can figure out which egit menu items are corresponding to these commands.
You wanted to pull and update the local master in the first laptop repository. You needed git checkout master first, which could be skipped if you were already on master and then git pull origin master. However you did git fetch origin master instead, which just updated origin/master with the new commit. It would have been okay to use git fetch origin master if git merge FETCH_HEAD or git merge origin/master followed imediately, because in many cases pull = fetch + merge, but you didn't.
I guess you then did git checkout origin/master. Checking out origin/master leads to detached HEAD state. To make it easier, you could just consider the detached HEAD as a nameless branch. When you make new commits, this namelss branch will grow. But you can't see these commits on other branches unless you apply these commits to them. Git has some commands to apply commits, including git merge, git rebase, git cherrypick, etc.
To fix the current situation, you can simply run git checkout master;git pull origin master.
So to make my answer more simply. Commit changes on your deateached head and make branch with this commit and then merge it together and push to master.
You can just download again your project if you didn't make changes on detached head that you need.

How to use Submodules with EGit

The Eclipse Team Provider for Git works but i do not see any changes for submodules when I use synchronize.
I see changes with the diff on the command line and also with tortoise i see the changes.
So, does anyone know ho to use Git and Eclipse in a way that synchronize and commit works with submodules?
The "Working with Submodules" section shows the submodules in the Git Repositories view:
From there, you have access to two actions:
Selecting the Update Submodule action on a submodule will check out the commit referenced in the parent repository's index for that submodule.
This command will also perform a merge or rebase if that has been configured in the update field for the selected submodule's configuration section in the parent repository's .git/config file.
Selecting the Sync Submodule action on a submodule will update the remote URL used by the submodule from the current value in the .gitmodules file at the root of the working directory of the parent repository.

Committing changes to branch I got by downloading zip from GitHub

I'm working on a repository that has two branches: Master, and Release1.
The branch I need is Release1. I went to the site and tried to clone it, but no matter what I did I got the Master branch cloned.
So I gave up and downloaded the branche's zip to my file system. I added it to Eclipse and worked on it.
Now I need to commit my changes. But neither the branch nor the repository show up in my visual tool.
When I try to add a local repository the visual tool tells me the folder is not a repository.
Is there a solution? I have quite a few changes on my local project and I have to commit them.
The Zip download is not a Git repository, it's only a collection of the files at that moment in time. Here's a way you might be able to get your changes into the repository:
Clone the repository properly
Copy your current files into the cloned directory
git status and git diff to check that the changes are what you expect
git commit
When you cloned the repository the first time, you were getting both branches - a Git clone is a fully copy of everything: every branch, all history, etc. The default branch is typically master. After you clone, if you want to switch to the other branch, use git checkout Release1.
What GUI are you using? When trying to clone you have to make sure you change the branch you are cloning from (usually in a drop down menu or you may have to type it in). If you can successfully clone from Master, than you should be able to change to or "checkout" Release1 branch.
Just downloading the zip, just gets you the source code and doesn't have any connection to git. To save and push your changes you will need to clone the repository and checkout Release1

Switch to another branch in EGit cannot work

I have Branch A and Branch B in the local branch folder.
Branch A is under working.
Now I want to switch to B.
The window pops out:
Checkout Conflicts
The files shown below have uncommitted changes which would be lost by checking out 'master'.
Either commit the changes, stash the changes, or discard the changes by resetting the current branch.
project.properties.
There are 3 options:
Commit..
Stash...
Reset
No matter which option I choose, it does not work.
For example, if I choose "Stash" option, it says:
"The repository does not contain any local changes to stash".
I suspect the egit records have some conflicts, so it cannot know how to do the next step.
The only way:
To remove the local branches, and clone the remote repository to the local?
This needs cost some time for downloading.
I had the same problem. EGit complaint about .class files which were not commited. I deleted the .class files and was able to switch to the desired branch without problems.
IMO removing local branch is not required.
I suggest first to pull the remote changes to local Branch A.
Resolve any conflicts while pulling the changes if any. Refer this video
Add your changes to Git staging area just by dragging the the files from unstaged area to staged area refer pic below.
Click on commit button, then push the changed to remote branch.
After doing this Branch A will be clean, then you can switch to Branch B just by double clicking on it or by right clicking on the repository node and selecting Switch to option in Git repository view.
Also I suggest to use the latest stable Egit plugin from here

How can I sync my custom CodePlex Mercurial fork against the main trunk?

I've made a fork of some codeplex project. Done some extra code, etc and have even pulled my custom code into the source control repo.
In those few weeks and months since i was working on my own fork, their main trunk has been updated.
how can i sync my code with that of the trunk?
(the main reason for me wanting to sync my code with the trunk is that they upgraded to vs2010 and i'm still using a vs2008 project version :( ).
I just ran into the same issue and ended up here. While the comments above lead to the correct answer, they may not cut it for a person new to Mercurial who wants to contribute to an open source project.
A plain hg pull would only pull any changes from your fork to your local cloned repository, not helpful in this case. There is an optional parameter [SOURCE] that allows you to pull from the trunk instead.
Here are the Mercurial command-line commands needed to do the job (replace "someprojectname" accordingly for your desired CodePlex project or, for similar systems, replace the entire URL with your fork's trunk's URL [vs. your fork's URL]):
[Optional] See what changesets are in trunk but not in your local repository: hg incoming https://hg01.codeplex.com/someprojectname
Pull new changesets to your repository: hg pull https://hg01.codeplex.com/someprojectname
Merge those changes into your own code (resolving conflicts accordingly): hg merge
Commit the results to your local repository: hg commit -m "Some message about merging changes from trunk."
Push the updated version of your code from your local repository to your fork on CodePlex: hg push