Getting Started

Undoing Changes

Undo latest commit using git revert HEAD ``` ~/code/gitfaffing % git log --oneline 481db44 (HEAD -> master) crazy edit of world.txt be880c6 added world.txt and edited hello.txt aa1a9d2 init ~/code/...


list branches git branch ` create (and checkout) new branch git checkout -b crazy-experiment ` delete branch (after merging) git branch -d crazy-experiment delete branch (not merged but you don...

Reset remote to an earlier commit

bash git reset --soft 64ad84e git commit -m "squashing a lot of commits" git push -f heroku master Of course, don't do this if there's more than one git collaborator in which case revert like this...

  • Updated almost 2 years ago by vince
Compare file between 2 branches

bash git diff branch1 branch2 path/to/file Compare local uncommitted file with another branch bash git diff rails610:./ -- Gemfile

  • Updated almost 2 years ago by vince
Convert local master into a branch

If you want to convert a local master branch (that is ahead of remote) into a branch bash git checkout master git branch experiment git reset --hard heroku/master git checkout experiment

  • Updated about 2 years ago by vince
Rebase experimental branches

Fake everyone (including yourself) by squashing stupid commits on your experimental branch and then merging a pristine commit to master git checkout -b crazy-experiment do lots of stupid commits ...

Checkout one from from a previous commit

git checkout c96a579 app/assets/stylesheets/menu.scss

  • Updated over 2 years ago by vince
Branch from a previous commit on master as though the branch was made before ...

remove the commits from master as though you had made the branch before those commits were made git checkout master git branch branch-name git reset --hard <sha1>

  • Updated over 2 years ago by vince
Git stash

takes your uncommitted changes (both staged and unstaged), saves them away for later use, and then reverts them git stash -u git checkout master git checkout crazy-experiment git stash pop stash ...

Change (Amend) commit message

if you just made a commit and want to change the message git commit --amend -m "better commit message"

  • Updated over 2 years ago by vince

Fast Forward Merge when you just have a simple branch from the master tip ``` Start a new feature git checkout -b new-feature master Edit some files git add <file> git commit -m "Start a feature" E...

Tips and Tricks

see compact tree of all your commits git log --graph --all --oneline --decorate if you do this a lot, you can add it as an alias ~/gitfaffing % git config --global alias.go 'log --graph --all --...

  • Updated over 2 years ago by vince
Working Directory, Staging Area, and Repository

(a) The working directory contains the files that are not handled by git. These files are also referred to as "untracked files." (b) Staging area contains the files that are going to be a part of t...