git mergebranch: Merge changes from branch to
actual branch
git mergetool: Working through conflicted files
Exporting and importing
git apply - < file: Apply patch from
stdin
git format-patchfrom [...to]: Format a patch
with log message and diffstat
git archiverev > file: Export snapshot of
revision to file
--prefix=dir/: Nest all files in the snapshot in
directory
--format=[tar/zip]: Specify archive format to use, tar or
zip
Tags
git tagname [revision]: Create tag for a
given revision
-s: Sign tag with your private key using GPG
-l [pattern]: List tags, optionally matching pattern
File status flags
Modified: File has been modified
Copy-edit: File has been copied and modified
Rename-edit: File has been renamed and modified
Added: File has been added
Deleted: File has been deleted
Unmerged: File has conflicts after a merge
Configuring
git config --global user.name 'name'
git config --global user.email 'name@email.com'
Use Git as a magic time
machine
1 2 3 4 5 6 7
git reflog # you will see a list of every thing you've # done in git, across all branches! # each one has an index HEAD@{index} # find the one before you broke everything git reset HEAD@{index} # magic time machine
Make the last
commit including the new changes
1 2 3 4 5
# make your change git add . # or add individual files git commit --amend --no-edit # now your last commit contains that change! # WARNING: never amend public commits
Change message of the last
commit
1 2
git commit --amend # follow prompts to change the commit message
Saving when committed
to the wrong branch
1 2 3 4 5 6
git checkout name-of-the-correct-branch # grab the last commit to master git cherry-pick master # delete it from master git checkout master git reset HEAD~ --hard
Undo a change to a file
1 2 3 4 5 6 7
# find a hashfor a commit before the file was changed git log # use the arrow keys to scroll up and down inhistory # once you've found your commit, save the hash git checkout [saved hash] -- path/to/file # the old version of the file will be in your index git commit -m "Wow, you don't have to copy-paste to undo"