Home > Mobile >  git reset hard, but no changes on graph when pushing
git reset hard, but no changes on graph when pushing

Time:09-16

I have a gitlab repo, made commit and merge.

I want to roll back my history my commit and merge history.

My local repo log.

I want to be on id: 9bc6dd4.

Attempts I am making:

git log --oneline --graph -5
git reset --hard 9bc6dd4
git clean -f -d
git fetch --all
git push -u origin  master

When I push to remote repo no changes on remote repo .

CodePudding user response:

Your question text has:

Attempts I am making:

git log --oneline --graph -5
git reset --hard 9bc6dd4
git clean -f -d
git fetch --all
git push -u origin  master

while your image marked "my local repo log" begins with:

user@user-dekstop:~Desktop/work/front$ git log --oneline --graph -5
*   4efe036 (HEAD -> development, origin/mybranch, ...) ...

provided I have not made any typos during transcription. That means your current branch is development, not master. Note the HEAD -> development text. Hence your git reset will adjust your branch name development. Your git push, however, says to push master to master (with --force via ). Since your own master did not move and still names the same commit as origin/master, this git push has no effect.

CodePudding user response:

If your intention is to revert the remote master branch to commit 9bc6dd4, there are several ways to do that :

a. just instruct git to force push 9bc6dd4 to master :

git push --force-with-lease origin 9bc6dd4:master

# anything that points to '9bc6dd4' can be used :
# after your 'git reset --hard' command : HEAD or development point to that commit
git push --force-with-lease origin HEAD:master
git push --force-with-lease origin development:master

b. switch to your local master branch first, reset your local branch, then force push :

git checkout master
git reset --hard 9bc6dd4
git push --force-with-lease

If your local master branch is set to track origin/master, then the last command will be equivalent to git push --force-with-lease origin master:master.

  • Related