Skip to content

Latest commit

 

History

History
59 lines (42 loc) · 6.6 KB

version-control.md

File metadata and controls

59 lines (42 loc) · 6.6 KB

For the sake of our future selves, let's

keep calm and apply version control methods

This page is a collection of ebooks, blogs and videos which the Transforming Publishing team have used to learn git and GitHub for version control ourselves. If you are new to version control then you might like to start with the resources marked with an asterisk * first. Using version control software comes with a new set of terminology (commits, branches, and so on... 🤷‍♀️). Don't worry if these seem alien at first - the more you use the tools below, the more these will make sense.

General

Version control allows us to keep a record of who edited a file, when and, most importantly, why. Whenever you create a new version of a file and give it a new name (e.g. 'file', 'file v2', 'file final', 'file actual final') you are practicing a form of version control. Version control software allows us to carry out a similar process, but without the need for multiple files, each with a slightly different name. Instead, the software does the heavy lifting to store a snapshot of your file (or files) at chosen points in time - all you need to do is tell it when to take these snapshots and write a short description of what was changed.

For some background on version control methods in general:

GitHub

Git and GitHub with RStudio

gitbash

Once you are familiar with the GitHub workflow and have had a bit of practice using the integrated buttons in RStudio, we would highly recommend trying out the command line. The integrated functionality of Git/GitHub with RStudio is excellent, but it does have some limitations. Learning a few basic git commands will give you a lot more flexibility, for example when using branches.

Improving your version control skills

For when you are ready to take your version control to the next level 💪

Advice on "Time travelling" with git

Use git revert to undo the changes made in a previous commit (this doesn’t need to be the last one). This doesn’t remove the commit, but adds a new commit that inverts the changes made previously. This is the best way to undo something as it retains all the history and you can do this within a branch and then merge it back into the master. The command is:

git revert –n <commit ref code>

The –n means "no commit" – so the changes are staged but you then need to run git commit –m “commit message” to commit these changes. You can run git revert without –n, however this will open the git bash editor and ask you to enter a commit message - you may prefer to commit manually.

Alternatively, you can use git reset to roll back the repo to a specific point in time. However, this deletes commits and so doing this within a branch causes problems when you want to merge back into the master as the branch is x commits behind. There are only two situations where using this would be sensible: if you’re working locally and haven’t pushed your commit to GitHub yet or if something major has gone wrong in the repo and a reset is done within the master branch. The following command also gives the option to delete changes altogether or delete commits whilst keeping changes staged or unstaged:

git reset –hard <commit ref code>

Remember, this will reset the branch to the referenced commit and delete all changes committed after this point so ⚠️ use with caution!!! ⚠️

For further reading on time travelling in git:

Git revert: https://www.atlassian.com/git/tutorials/undoing-changes/git-revert

Git reset: https://www.atlassian.com/git/tutorials/undoing-changes/git-reset