Reputation: 11
I found that when I try "git pull origin master" command, sometimes the most recent commit is removed. It happens when I merge a local branch to the master, then pull from the remote origin.
Firstly I created a git repository with first commit. Currently local HEAD and origin/master points to the first commit (up to date).
$ git log --oneline --all --graph --decorate
* d42ad4e (HEAD -> master, origin/master) First commit
Then I created a branch (branch name "test"), made a simple change and commit, and merged to the master. After then, commit history looks following.
$ git log --oneline --all --graph --decorate
* ea13eb8 (HEAD -> master) Merge branch 'test'
|\
| * 9d3969f (test) test
|/
* d42ad4e (origin/master) First commit
As you can see, 9d3969f is the commit I made on test branch, and ea13eb8 is created via "git merge test" command.
Then if I use "git pull origin master" command,
$ git pull origin master
From https://github.com/????/????
* branch master -> FETCH_HEAD
Successfully rebased and updated refs/heads/master.
$ git log --oneline --all --graph --decorate
* 9d3969f (HEAD -> master, test) test
* d42ad4e (origin/master) First commit
The change applied as I wanted, but commit ea13eb8 is deleted now. I'm just curious what happens to the most recent commit when I pull from the remote origin.
Upvotes: 1
Views: 340
Reputation: 832
It seems like you use git pull
using rebase
.
Please refer git rebase has empty commit behaviour
By default git has git merge
behaviour which adds merge commit.
Upvotes: 0
Reputation: 522171
The feedback you are getting from Git might partially reveal what is happening here:
Successfully rebased and updated refs/heads/master.
It appears that your pull strategy is using rebase, rather than a simple merge. As a result, when you git pull
, a rebase is happening, which can rewrite history and also move around commits. Check you .gitconfig
file for an entry looking something like this:
[branch]
autosetuprebase = always
You may also run the following to check your Git configuration:
git config --list
If you don't want the current behavior, then maybe it is time to change your settings. Or, you could explicitly pull via the merge strategy using:
# from master
git fetch origin
git merge origin/master
Upvotes: 1