1

I'm trying to figure out Xcode's Source Control feature for local, non-remote, git work, and I'm confused by the process of reverting back to old commits.

Say my project has a single branch, main. And say my project has a number of commits. I decide I want to revert the project back to the initial commit. I go into the Source Control Navigator, I right-click the initial commit and I select New Branch from.... I now have two branches, main and initial-commit-branch. I switch back to main, and right-click the new branch and select Merge initial-commit-branch into main branch. I get an error that says "the repository already contains all changes". What am I missing here?

HangarRash
  • 7,314
  • 5
  • 5
  • 32
lurning too koad
  • 2,698
  • 1
  • 17
  • 47

1 Answers1

1

All commits on initial-commit-branch already exist on main, so Xcode is right that there is nothing to be done. This is the same as if you had tried to perform the merge yourself with Git on the command line. A merge is not a rollback.

If you want to reset main to where initial-commit-branch is with Xcode itself, you can delete the main branch and rename initial-commit-branch to main. If you have already pushed initial-commit-branch, you would need to delete the remote branch and set the upstream to origin's main, then force push.


You can reset main back to the initial commit with Git on the command line:

git checkout main && git reset --hard <sha>

where <sha> is the original commit hash. More details are given in How to roll back Git repo to first commit and delete all history.

grg
  • 5,023
  • 3
  • 34
  • 50