Chris_1983_Norway
Chris_1983_Norway

Reputation: 399

Xcode 9.2 - Version control - how to revert back to earlier committed version

Im using Xcode 9.2 with bitbucket for version control. I have the past 4-5 hours worked in the master branch. I realise now that I want to keep the work that I have done today but not part of the master branch but rather as a new branch.

I have been able to push the existing version to the new branch, but it required me to commit to master first (locally).

Now I want to revert the master back to the version from yesterday, and commit this at the master. This is where the problem occur. I am able to revert back to the previous committed version by checkout the commit - but then I am not on the master branch anymore, and I can't commit to master or push to master.

How can I revert back to the master to a previous build, and basically remove the changes done the past 4-5 hours?

Upvotes: 1

Views: 2230

Answers (1)

Dominik Bucher
Dominik Bucher

Reputation: 2167

For the next time you realise before you commit:

  1. Open up terminal
  2. cd ${path to your project}
  3. run git stash command
  4. When you stash the not commited changes, now you should be safe to switch and make new branch
  5. now change to the new branch and apply stash: git stash apply
  6. Enjoy your changes.

Since I am confused as hell and this happens to me from time to time, I created alias in my .bash_profile file to delete the local commits by simply making one command in terminal:

alias fixFuckup="git reset HEAD~1"

simply run the command and you will be reset to the state before the commits. Actually this resets one commit.

git reset HEAD~1

to reset to the state before doing lot of commits, prefer using this.

git reset --hard HEAD^

for clarifying the changes please take further look at this:

what is difference between 'git reset --hard HEAD~1' and 'git reset --soft HEAD~1'?

Upvotes: 3

Related Questions