3

I thought Amend last commit in Sourcetree is just for "last commited message" and used it while commiting. But it raised the following error

enter image description here

I tried to pull from remote, but got "cant pull from unrelated histories".

My question is, Do Amend last commit does more than just a message? Why unrelated history error came?

Rajana Deepak
  • 1,302
  • 2
  • 13
  • 28

1 Answers1

3

An amend last commit would by default trigger an "behind its remote counterpart" error on git push, if that mast commit was previously pushed.

It changes the last commit done:

-x--x--x (master, origin/master)

Change the last commit with amend:

-x--x--X' (master)
     \
      x   (origin/master)

"can't pull from unrelated histories" can happen if the remote repository has only one commit: changing the local one means: no common ancestor.
(If not, read "“refusing to merge unrelated histories” failure while pulling to recovered repository")
You can pull allowing for unrelated history to be merged

git pull origin master --allow-unrelated-histories
git merge origin origin/master

... or you can simply, if you are the only one working on the remote repo, force the push.

git push --force
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250