2

git push does not push latest commit to remote.

Steps to reproduce:

  1. With a local project, last commit amended a few times before push.
  2. Create a new empty project. (in gitlab)
  3. Add the new project origin.
  4. git push -u [origin] [branch].

Problem:

git keeps push outdated commit to remote! Not the commits I locally amended before push.

How can I force git to cleanup and don't remember the stale commits?

Added Information: git 2.1.0

user2771324
  • 307
  • 3
  • 13
  • What git branch returns? Are you in a detached head mode? (http://stackoverflow.com/a/3965714/6309) – VonC Sep 19 '15 at 15:19
  • I tried to "git remote rm" all other remotes. I don't know if no remote is detached head state. As for the push target, it is a newly created project and a newly added origin, so it should not have a valid HEAD yet. – user2771324 Sep 19 '15 at 15:26
  • I meant: what does the command `git branch` return? In your local repo. Nothing to do with any remote for now. – VonC Sep 19 '15 at 15:27
  • You can't delete a commit once it is pushed. You should probably create a new project in Gitlab and push to it – edi9999 Sep 19 '15 at 15:34
  • yes. git branch shows detached state( – user2771324 Sep 19 '15 at 15:35

1 Answers1

2

git branch shows detached state

That would explain why pushing a branch to any remote would push an "outdated" commit: the branch still refer to the old commit, while the new amended commit (referenced by HEAD) is detached from any branch.

You can force a branch to reset to the current HEAD

git branch -f master HEAD

That would reset the branch master to the current amended commit.

Then you can create a new Gitlab repo, and git push -u origin master.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • So the last param in git push, if not A:B, means local refs? I thought it is sort of remote refs. – user2771324 Sep 19 '15 at 15:56
  • @user2771324 in your case, it is the local `master` branch. In general, the last parameter is a **refspec**: The format of a `` parameter is an optional plus `+`, followed by the source object ``, followed by a colon `:`, followed by the destination ref ``. The `` is often the name of the branch you would want to push, but it can be any arbitrary "SHA-1 expression", such as `master~4` or `HEAD`. – VonC Sep 19 '15 at 16:02