If you want to version some files like a website project you’re working on, Git works really well. No remote server is needed and everything is self-contained by folder.
- Create a new, empty folder
- Run git init (a hidden .git subfolder will get created which will store all versioning information this new repository)
- Create a file, e.g. test.txt, write “line 1” in it and save it.
- Run git status (you’ll see one untracked / unversioned file)
- Run git add text.txt or git add . (test.txt or all files within the current directory will get added / staged for committing)
- Run git status (you’ll see text.txt is ready to be committed)
- Run git commit -m “Added one line” (text.txt will get committed)
- Run git status (you’ll see that there’s nothing ready to commit and the working directory is clean)
- Edit the file and write “line 2” on line 2 and save it
- Run git status (the file will status will be “modified”)
- Run git checkout — test.txt (the changes – line 2 – will be reverted / undone)
- Edit the file again and write “line 2” on line 2 and save it
- Run git add . followed by git commit -m “added line 2” (the modified file is added and committed)
- Run git log (a log of all commits included commit messages and signatures is displayed)
C:\Users\ayahya\Documents\temp>git log
commit 78f7d5cd1f9cbec2cc7a55a3e5cd6dd12b2ea13d
Author: unknown <[email protected]>
Date: Fri Mar 20 16:29:39 2015 -0700
added line 2
commit 2587182fe50b7f1ae01b3153f637fd3abcbe2120
Author: unknown <[email protected]>
Date: Fri Mar 20 16:13:46 2015 -0700
Added one line
- Run git diff 78f7d5cd1f9cbec2cc7a55a3e5cd6dd12b2ea13d 2587182fe50b7f1ae01b3153f637fd3abcbe2120 (and you’ll see a standard diff between the two commits)
- If you want to move your repo to another folder or computer, just copy the whole folder containing the hidden .git subfolder.
For more info, visit the Git documentation or this ebook.
For a visual understanding of Git, check this out.