Git Branches and Textmate: Trying Out Experiments on Code and Undoing Changes on Textmate
The lesson for today boys and girls is this…
Problem: Undo code changes in an app using a branch.
I cloned an app. I wanted to make changes on the code. But wanted to roll back to before-the-changes in case I broke the app.
I use TextMate so I wanted to see the difference of the changes or maybe see the 2 branches to compare the before and after.
Solution 1: Use git reset HEAD –hard
@desireco offers this solution
First create a branch to make those changes
$ git branch
Shows:
* master
Create a branch
$ git branch other_branch
$ git branch
Shows:
* master
other_branch
Move to other_branch
$ git checkout other_branch
Now make changes in Textmate
Now you can update code in any file of the app. Test the changes on the localserver.
If you are happy with the changes on the other_branch
add, commit and merge to master.
If you are not happy with the changes on the other_branch
$ git status
This checks for untracked files.
You would need to add the files to git with:
$ git add .
Then you can undo the changes by:
$ git reset HEAD --hard
It would say something like “HEAD is now at…” It will show the latest commit on the master branch.
Solution 2: As an alternative you can keep track of changes using Gitx
@j_mccaffrey offers this solution
Use Gitx to keep track of the changes on the branches.
Install it and “After starting GitX, you can install the command-line tool through the menu (GitX->Enable Terminal Usage…). This will install a “gitx” binary in /usr/local/bin.
In the terminal, under the app folder run
$ gitx
It would open up a UI window where you can see the changes on the branches. You can see the code that was added and that was deleted on each file, on each branch.