I've got a Bitbucket repo that needs to be git reset --hard
to a specific commit. Prior to this operation, I had this:
% git status
On branch master
Your branch and 'origin/master' have diverged,
and have 16 and 15 different commits each, respectively.
(use "git pull" to merge the remote branch into yours)
nothing to commit, working tree clean
I ran the git reset --hard
command locally with a commit ID like this:
git reset --hard 798cd84
Then I ran git pull
and the expected fast-forward occurred.
Updating 798cd845..22bd077a
Fast-forward
.
.
.
24 files changed, 705 insertions( ), 80 deletions(-)
After that, I did git status
and saw that it was saying
% git status
On branch master
Your branch is up to date with 'origin/master'.
nothing to commit, working tree clean
but there was no change locally to git log
. I tried git commit -m "my comments"
and that resulted in nothing being committed, obviously.
On branch master
Your branch is up to date with 'origin/master'.
nothing to commit, working tree clean
On Bitbucket there was no change, again obviously, because I didn't have anything to push. But when I try to push anything, nothing goes to the remote. It just says Everything up-to-date
.
So, how do I effect this change on the remote if there's nothing locally that I can do with git commit
or git push
?
If I've severely messed this up, how do I get back to good locally so I can try something else?
CodePudding user response:
If I understand your confusion correctly, I think the key is this line:
Your branch and 'origin/master' have diverged, and have 16 and 15 different commits each, respectively.
So, there was a common history on both versions of the branch, and then:
- 16 commits in your local history
- 15 commits in the remote history
Given how similar the numbers are, it's fairly like that 15 of the 16 local commits were parallel versions of the 15 remote commits. That is, either you or someone else has run git rebase
or a related command, and created new versions of those commits.
So, when you discarded your 16 commits, and pulled in the remote 15 commits, most of the log history will look the same - all the same commit messages, authors, and authorship dates, except for that one extra commit which you've discarded.
In other words, it only looks like syncing up with the remote branch made no difference because it was already very similar.
CodePudding user response:
what about using this command to restore to a previous commit? git checkout 798cd84 then with this command you can restore to that commit in another branch(not main) and you can change it and merge it to main and finally push it to your repo...