0

Step 1 : I have created a Local Git repository

Step 2 : Then I did a Pull(current branch is master)

Step 3 : After that I have reverted the merge by using Reset as shown below on the local copy.

enter image description here

Step 4 : After that it shows correctly as shown below.

enter image description here

Q : I tried to push the changes to remote master. It gives below error. Could you tell me why? I'm using TortoiseGit. Thanks.

enter image description here

Yue Lin Ho
  • 2,479
  • 23
  • 32
Sampath
  • 50,641
  • 40
  • 250
  • 357

4 Answers4

3

I have found out the solution.Here are the steps.

Step 1 : Clone the remote repository (will be checked out on default branch master automatically)

git clone https://github.com/myrepo/myrepo.git

Step 2 : reset the local master - it will change the master to point to a different commit with specific SHA.

git reset --hard 2f89f2971c3cr45fe187241b8cb89a8ef8234ea3

Step 3 : push back to remote repository.

git push https://github.com/myrepo/myrepo.git --force

This article helped me a lot : Undoing Merges

That's it.All are done.Cheers :)

ItayB
  • 6,914
  • 7
  • 41
  • 59
Sampath
  • 50,641
  • 40
  • 250
  • 357
  • 1
    Just terminology notes: you are not cloning branch - you are clonning repository (myrepo) - its default branch is master so it might confuse a bit. Then, you have changed the master to point on diff commit ( by giving its SHA). Last thing was to push the master of your local repo to your remote repo. – ItayB Apr 22 '16 at 04:31
  • 1
    @ItayB Thanks for the info.Please modify the above post.Then we can get more knowledge about the `Git Terminology`.Thanks in advance. – Sampath Apr 22 '16 at 07:28
  • I had a very similar issue on WebStorm. **Steps 2** and **3** did the trick (step 1 was not needed) – Ricardo Nov 01 '17 at 22:45
0

This is a sticky situation. You can't revert the remote repository in this way because the remote recognizes that the state of your repository is behind. There's undoubtedly better solutions, but you can delete the remote repository, create a new remote repository with the same name, and then push your local repo to it.

Jeff Puckett
  • 28,726
  • 15
  • 96
  • 149
0

you can checkout each of the files that were changed from your previous commit to which you would like to revert, and then make a new commit.

I'm not familiar with toroisegit, but I presume it has a command line input somewhere, so the steps would be something like this:

Let's say that the hash of commit you want to revert to is 29edf27 And you changed two files that you want to revert, say file1.php and file2.txt

git checkout 29edf27 -- file1.php
git checkout 29edf27 -- file2.txt
git commit -m "reverted commit to 29edf27"
git push origin master
Jeff Puckett
  • 28,726
  • 15
  • 96
  • 149
  • This is not clear for me.I have reverted the changes correctly on local no ? So why do I need to do it again ? Thanks. – Sampath Apr 21 '16 at 15:39
  • by reverting your changes on local, you merely checkout a previous commit. so from the remote's perspective, you're an outdated client because the tip of your branch is older than its tip. the above procedure will create a new commit which includes the HEAD commit on the remote as a previous commit, so the remote will recognize that your local repo has everything it does as well as new commits. – Jeff Puckett Apr 21 '16 at 16:54
  • to clarify, I think the term "revert" may be non-intuitive in this instance. you're not really reverting anything per se, as in conceptually discarding changes, but in fact you're simply checking out an older version of the repository. you could by this process "un-revert" by checking out the newest commit hash – Jeff Puckett Apr 21 '16 at 16:57
0

After hard reset branch to chosen commit, you should just force push your changes.

VCS - Git - Push - Force push