Reputation: 4629
I have an issue in which whenever I run git pull in my production server, it will result in a merge.
If I run git status, I get the following output:
$ git status
# On branch master
# Your branch is ahead of 'origin/master' by 351 commits.
# (use "git push" to publish your local commits)
#
nothing to commit, working directory clean
Ok, so there are 351 local commits. But git diff doesn't show any local changes:
$ git diff origin/master..HEAD
(no output)
If I use git log origin/master..HEAD, I only see messages like "Merge branch 'master' of ****".
Any ideas about how can I get rid of those 351 local commits which seems to be useless?
Upvotes: 6
Views: 2385
Reputation: 124824
First of all, just in case, let's create a backup of your current branch:
git branch master-bak
If git diff origin/master..HEAD
gives empty output, that means your current branch has identical content as origin/master
. In which case, you can simply reset your local branch to the same state as origin/master
:
git reset origin/master
Upvotes: 6
Reputation: 1888
When git status says that your branch is ahead of 'origin/master' by 351 commit, it actually does mean origin/master. simply it means there is pointer named origin/master in your repo pointing to the commit which is the HEAD of that remote branch, and your master is ahead of this commit.so when you run git pull then your local changes will also merged. and in this case you need to checkout a new branch or commit again after merge.
Upvotes: 0
Reputation: 5357
Obviously you are not working alone so someone did a forced push (your local repo has different history from the remote), after which everyone else should do git reset --hard origin/master
, so as to keep the same history with the origin/master.
Upvotes: 1
Reputation: 255
I guess after the last time you pull remote master, the origin/master had some revert thats why. If you want to be up-to-date with remote master just delete local master and create new one.
git checkout another branch
git branch -D master
git checkout -b master
git pull origin/master
Upvotes: 0