1

I have pushed 3 commits in the remote repo and I am worry of the result on what effect does 3 pushed commits will do. Will the first commit will be applied or the latest commit? thanks. what should I do?

baddong
  • 29
  • 1
  • 6

4 Answers4

1

If the remote repo didn't changed since your last push, a git push will be a fast-forward merge, meaning the remote origin/<remoteBranch> HEAD will simply move to reference the most recent of the 3 commits.

Otherwise, you would need to pull first (merging origin/<remoteBranch> to your branch in order to create a 4th commit), and you would push back.

The third commit/latest commit is the correct commit, so I shouldn't worry on it?

Yes, that will be the one defining the state of the repo cloned by other: they will see the repo as defined by the third commit.

I actually did what you said, when I realized that my 2nd commit is wrong.
I made a third commit assuming that this last commit will be the last to applied not the 1st and the 2nd one.

All are applied sequentially. The final state of the repo will be defined by the last commit pushed.


To recap:

If your three commits (including the 2d "wrong" one) and the correct third one are done on the branch you are pushing to remote, all three will be on remote, but the users will clone that remote repo at the state defined by the third commit:

       1--2--3 (master)         => push   => x--x--1--2--3 (master)
      /                                                    (origin/master)
  x--x  (origin/master)
Community
  • 1
  • 1
VonC
  • 1,042,979
  • 435
  • 3,649
  • 4,283
  • ok thanks @VonC so I should have not to worry? cause I am new to git and really nee help. – baddong Jan 29 '15 at 07:18
  • No need to worry: if your repo looks good locally, it will look the same on the remote side when pushed. – VonC Jan 29 '15 at 07:21
1

All. When you push commits, you do just that. Each commit is pushed exactly as they are in your local repository. All repositories are identical, except for what's not yet pushed/pulled.

If the remote as new commits after your last pull you need to pull first and then push.

Andreas Wederbrand
  • 33,680
  • 10
  • 58
  • 75
  • 1
    If you share the repository with anyone else I'd say no, better to correct the errors and push a new commit. If it your personal repository then remove the two bad commits locally and do a forced push, `push -f` – Andreas Wederbrand Jan 29 '15 at 07:01
  • I it shared repo. The third commit/lates commit is the correct commit, so I should't worry on it as you have said @Andreas Wederbrand? I actually did what you said, when I realized that my 2nd commit is wrong I made a third commit assuming that this last commit will be the last to applied not the 1st and the 2nd one. Am I right? – baddong Jan 29 '15 at 07:06
1

When pushing commits all your commit are sent in same order you create them.

philippe lhardy
  • 2,866
  • 23
  • 34
  • yes. and push pushes all pending commits : commit commit commit push is same as commit push commit push commit push. [ considering there is not conflicting commits from other sources ]. – philippe lhardy Jan 29 '15 at 09:24
1

After first commit, without changing the file if you want to perform commit, this will give you a warning: "No changed items were selected. Do you wish to amend the last commit?" I hope you got this. Then if you go for yes option, then it will re-commit and update the pointer.

You can check the changes in Gitblit, if it is configured for you.

Also if your committed file is correct (has same code) then nothing to worry.

Varun
  • 95
  • 7
  • My last pushed commit is the correct commit. What will happen to the first and second commit? – baddong Jan 29 '15 at 06:56
  • will it affect the latest commit w/c is the correct commit? – baddong Jan 29 '15 at 06:57
  • First and second commit will also be there in the repository with previous version, and Head will point to latest commit. – Varun Jan 29 '15 at 06:59
  • If another user, take an update then will get latest committed file. That is the use for shared repository. – Varun Jan 29 '15 at 07:02
  • ok so when merging it to the master all 3 will be there but the last will be on top? – baddong Jan 29 '15 at 07:09
  • No, if you are working on branch and then you will merge this branch to master only the latest (top) one will be available in Master. In branch you can see all 3 and latest on top. – Varun Jan 29 '15 at 07:14
  • So this is good news to know that the latest will be on master and the 2nd and 3rd will only remain in my branch. thanks @Varun – baddong Jan 29 '15 at 07:21