Git & Tower - A Safety Net for Your Projects
Discarding Local Changes
When editing your code, you won't always get everything right the first time. Sometimes, you have to admit that you have to start over. Restoring the last committed state of a file is one indispensable feature of version control.
However, since local changes haven't been saved in your Git repository, you must keep in mind that discarding these kinds of changes can't be undone.
Discarding All Local Changes
If you want to throw away all local changes and restore your complete project to the last committed state, you can simply right-click the "Working Copy" item in Tower's sidebar. Then choose "Discard All Local Changes…" from the contextual menu.
Discarding Changes in a Single File
If you only need to discard the modifications in a single file, you can right-click it in the "Working Copy" list of files and select "Discard Local Changes…" from the contextual menu.
Discarding Parts of a File
In many cases, you'll only need to undo parts of your changes. That's when Tower's "Discard Chunk" feature comes in handy.
When selecting the corresponding file in the "Working Copy" list of files, the right area presents you the detailed diff of the current changes.
You can now discard any chunk of changes: clicking one of the "Discard Chunk" buttons will discard just the respective part in the file!
Restoring Previous Versions of a File
The "History" view takes you back in time: select any historic commit in the list and switch to "Tree" mode on the top right of the window. You will then see all of your project's files at this point in time!
In case you want to restore one of the files from such a historic state, you can right-click it and select "Restore <filename>…".
Undoing Committed Changes
When you want to undo a commit, you basically have two options: revert and rollback. Both can be accessed by selecting your current HEAD branch in the sidebar, then right-clicking the commit in question.
Let's see how these options work:
Rollback
A "rollback" restores your project just like it was at some defined version in the past. All commits that came after this version will be undone. This makes a rollback quite a drastic method. Consider creating a new branch on which you can perform this to avoid shooting yourself in the foot.
When you're ready, simply right-click the commit you want to return to in the list and choose the "Reset HEAD…" option.
Revert
The "revert" feature solves a different problem: You might have one particular commit that you want to undo - but you don't want to touch any other commits that came after it. Revert solves this problem by creating a new commit that contains opposite changes - essentially reverting the effect of those changes. E.g. if you deleted some lines in a certain commit, reverting it will create a new commit that adds exactly these lines, again.
In Tower, you can right-click any commit in the listing (again, make sure that your current HEAD is selected in the sidebar) and select the "Revert…" option.
Fixing the Last Commit
It's all too easy to mistype a commit message. Or to forget adding a certain change. However, it's just as easy to correct these kinds of mistakes in Tower!
Git offers an "amend" feature that allows you to fix the very last commit you made. Accessing this in Tower is simple:
- If you want to add more changes to the last commit, simply stage them as usual in the "Working Copy" view. If you only want to modify the last commit's message, make sure you have no staged items.
- Expand Tower's commit interface (by focussing the subject textfield - or simply pressing CMD+SHIFT+C).
- Check the "Amend" option at the bottom.
- You'll notice that this will restore the last commit's message in the text fields.
- If you want, you can now also modify the message, e.g. to correct some typos.
Confirming the dialog will then replace the old, incomplete commit with your fixed version. However, to avoid problems, you should remember one simple rule: don't amend commits that have already been pushed to a remote repository!
The Result: Confidence
Knowing that you can undo almost everything at every point in time let's you sleep easy at night.
Tower takes this one step further by making it incredibly easy to do. If you haven't already: Take Tower for a test drive - free for 30 days!