-1

I'm new in Git, and I just did a wrong push or commit. I cannot distinguish which mistake I made.

Assume that the original correct version is A, and the later wrong one is version B. When I clone the files using 'git clone', the files are version A. However, when I view from the Git Bitbucket website. The site says it was already changed to version B.

Can anyone suggest why it looks like this? I've checked the answer below. If remote repository means the result i found from the website? What are the differences between "git commit" and "git push"?

And I would like to have the version B in website back to version A. What should I do? Undo a commit or undo a push....

cindy50633
  • 144
  • 2
  • 11
  • Are you in the same branch? When you do a git clone by default you are in the master branch. If you want to switch to another branch use git branch NameOfTheBranch. If this is not the case, it can also be that you did the git clone before the push job was finished. You can try deleting the dir and doing again the git clone – pcampana Nov 28 '18 at 08:42
  • This happens in the same branch. If the push job wasn't be finished, does this mean that the Bitbucket changes the contents it appears without influencing the result of cloning if I just finish the commit stage? And it means that I can just undo the commit step to make it back to the previous version? – cindy50633 Nov 29 '18 at 00:22
  • If after the commit and push you can see the changes in Bitbucked website it means the push was done correctly. So as you can see in the website, you can see the diferent commits of your code, and ansering the question YES, you can return to all the previous versions of the code you can see in Bitbucked website – pcampana Nov 29 '18 at 11:26

1 Answers1

0

You can use reset to create the correct state of the index to make the commit:

#use this command to check the id you want to use. Imagine is 56e05fced
git log --oneline

git reset --hard 56e05fced

git reset --soft HEAD@{1}

git commit -m "Revert to 56e05fced"

In this link you can check what do you exactly need: git undoing

pcampana
  • 2,413
  • 2
  • 21
  • 39