V
V
Valera Udav2016-04-20 17:12:42
git
Valera Udav, 2016-04-20 17:12:42

How to overwrite old commits in git?

The situation is as follows:
I was developing in the master branch , after which it was necessary to rollback three commits back due to their uselessness, I did this with the git checkout command . Further, I already led the development and made commits from the rollback point.
Problems arose when I decided to push the changes. Starting to throw an error:

fatal: You are not currently on a branch.
To push the history leading to the current (detached HEAD)
state now, use

    git push origin HEAD:<name-of-remote-branch>

Later I decided to check what I was swearing at and through the git branch command I found out that I was not at all in the master branch, but in some (HEAD detached from 2c38d2f) which, apparently, was created as an alternative branch.
The question is: how can I adequately merge my changes into master now ?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
ManWithBear, 2016-04-20
@TARAKANhoy

git checkout -b tmp
git checkout master
git checkout -b master_old
git checkout master
git reset --hard COMMITHASH // последний полезный комит из мастера
git merge tmp
git branch -d tmp
git push --force origin master

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question