问题
So let me set up my scenario. I am using EGit 4.1.1 in Spring Tool Suite (Eclipse 4.5.1). My tech-savvy coworker and I have cloned the same git repository from a remote URL. My tech-savvy coworker, who prefers the command line, does his file modification using VIM, then issues the commands
git add .
git commit -m "Modified file"
git push
Now the change is in the remote repository. Now I, who am less CLI-prone and more prefer the GUI, am using EGit in Eclipse. To receive the change, I right click the project (which I originally cloned using EGit), go to Team -> Pull, and I am told that there is "Nothing to fetch". For sanity purposes, I have the "Git Reflog" view open, and I see that my coworker's change is not listed, and I begin to scratch my head.
So I go to the command line and I issue the command git pull
, and voila!, it pulls in my coworkers change:
remote: Counting objects: 27, done.
remote: Compressing objects: 100% (10/10), done.
remote: Total 14 (delta 4), reused 0 (delta 0)
Unpacking objects: 100% (14/14), done.
From git://hostname.domain.com/git-repo
* branch master -> FETCH_HEAD
Updating 123ae12..68cd2f0
Fast-forward
Better yet, I go back to Eclipse, and I see the change in the "Git Reflog" view, listed as
Commit Commit Message Date Reflog Message
---------------------------------------------------------------
68cd2f0 Modified File 2015-12-23 pull: Fast-forward
So, I feel like what I am being told here leads me to believe that there is a Git concept that I am not familiar with - something that I'm probably just missing. So...
- Is there anything obvious I am missing here about the workings of git?
- I am assuming that fast-forward means I am just moving my HEAD forward in the same branch
- How do I accomplish this command-line "git pull" in Eclipse?
Edit: To address VonC's answer, I have added this information that is both more information and a solution to this question.
From the command line, when I run (from the repository) cat ./.git/.gitconfig
, I get the following output:
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
ignorecase = true
[remote "origin"]
url = git://hostname.domain.com/git-repo.git
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
remote = origin
merge = refs/heads/master
However, when I go into Eclipse and look at the fetch configuration, it is blank.
回答1:
First, the reflog would not show you anything before a fetch (in command line or Eclipse): it records changes from the local clone only.
Second, check your .gitconfig to see how the remote origin is configured (also seen here).
You need to have a line for fetching:
fetch = +refs/heads/*:refs/remotes/origin/*
By default, the command line git fetch would use the current branch:
refs/heads/<head>:refs/heads/<branch>
回答2:
To add to VonC's answer, what this means is that I missed a step when I originally configured the remotes for the git repo when I used EGit to configure it. Since I didn't have fetch configured for the repo, Eclipse was giving me the error "Nothing to fetch" - where perhaps it should have given me a more meaningful error like "Fetch not configured for this repository. To configure, you must..." Maybe I'll fix that later since EGit is open source.
To fix this in Eclipse (EGit), do the following:
- Ensure the Git Repositories view is open.
- Select the specific git repo, and expand it till the specific remote in remotes is expanded:
- Right click the incoming origin and choose Configure Fetch
- In the dialog, if you see no fetch configured at all, select Add next to the Ref Mappings pane
- In the dialog, for Source, type
refs/heads/*
(despite the "Not found in remote repository" message. Select Next. - For Destination, make sure
refs/remotes/origin/*
is filled in (it may auto-populate). Make sure Update the local repository even if data could be lost is checked. Click Finish. - Now in your Configure Fetch dialog, you will see the new ref mapping:
+refs/heads/*:refs/remotes/origin/*
. This matches what is in the .gitconfig file. - Now click Save if you plan to fetch later, or Save and Fetch if you would like you update your local repository.
I'm not totally sure why EGit didn't do this automatically, perhaps that's a question for another day.
来源:https://stackoverflow.com/questions/34447447/egit-issuing-a-fast-forward-pull-how-to-configure-fetch-for-a-remote-reposito