Reputation: 163
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
Upvotes: 1
Views: 2005
Reputation: 30858
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
.
Upvotes: 1
Reputation: 389
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.
Upvotes: 0