rys-git-tutorial/quick-reference.txt
2020-09-02 10:08:39 +02:00

83 lines
5.3 KiB
Text
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

The Basics
git init#Create a Git repository in the current folder.
git status#View the status of each file in a repository.
git add <file>#Stage a file for the next commit.
git commit#Commit the staged files with a descriptive message.
git log#View a repositorys commit history.
git config --global user.name "<name>"#Define the author name to be used in all repositories.
git config --global user.email <email>#Define the author email to be used in all repositories.
Undoing Changes
git checkout <commit-id>#View a previous commit.
git tag -a <tag-name> -m "<description>"#Create an annotated tag pointing to the most recent commit.
git revert <commit-id>#Undo the specified commit by applying a new commit.
git reset --hard#Reset tracked files to match the most recent commit.
git clean -f#Remove untracked files.
git reset --hard / git clean -f#Permanently undo uncommitted changes.
Branches I
git branch#List all branches.
git branch <branch-name>#Create a new branch using the current working directory as its base.
git checkout <branch-name>#Make the working directory and the HEAD match the specified branch.
git merge <branch-name>#Merge a branch into the checked-out branch.
Branches II
git commit -a -m "<message>"#Stage all tracked files and commit the snapshot using the specified message.
git branch -D <branch-name>#Force the removal of an unmerged branch (be careful: it will be lost forever).
Rebasing
git rebase <new-base>#Move the current branchs commits to the tip of <new-base>, which can be either a branch name or a commit ID.
git rebase -i <new-base>#Perform an interactive rebase and select actions for each commit.
git commit --amend#Add staged changes to the most recent commit instead of creating a new one.
git rebase --continue#Continue a rebase after amending a commit.
git rebase --abort#Abandon the current interactive rebase and return the repository to its former state.
git merge --no-ff <branch-name>#Force a merge commit even if Git could do a fast-forward merge.
Rewriting History
git reflog#Display the local, chronological history of a repository.
git reset --mixed HEAD~<n>#Move the HEAD backward <n> commits, but dont change the working directory.
git reset --hard HEAD~<n>#Move the HEAD backward <n> commits, and change the working directory to match.
git log <since>..<until>#Display the commits reachable from <until> but not from <since>. These parameters can be either commit IDs or branch names.
git log --stat#Include extra information about altered files in the log output.
Remotes
git clone <remote-path>#Create a copy of a remote Git repository.
git remote#List remote repositories.
git remote add <remote-name> <remote-path>#Add a remote repository.
git fetch <remote-name>#Download remote branch information, but do not merge anything.
git merge <remote-name>/<branch-name>#Merge a remote branch into the checked-out branch.
git branch -r#List remote branches.
git push <remote-name> <branch-name>#Push a local branch to another repository.
git push <remote-name> <tag-name>#Push a tag to another repository.
Centralized/Distributed Workflows
git init --bare <repository-name>#Create a Git repository, but omit the working directory.
git remote rm <remote-name>#Remove the specified remote from your bookmarked connections.
git remote rm <remote-name>#Remove the specified remote from your bookmarked connections.
Patch Workflows
git format-patch <branch-name>#Create a patch for each commit contained in the current branch but not in <branch-name>. You can also specify a commit ID instead of <branch-name>.
git am < <patch-file>#Apply a patch to the current branch.
Tips & Tricks
git archive <branch-name> --format=zip --output=<file>#Export a single snapshot to a ZIP archive called <file>.
git bundle create <file> <branch-name>#Export an entire branch, complete with history, to the specified file.
git clone repo.bundle <repo-dir> -b <branch-name>#Re-create a project from a bundled repository and checkout <branchname>.
git stash#Temporarily stash changes to create a clean working directory.
git stash apply#Re-apply stashed changes to the working directory.
git diff <commit-id>..<commit-id>#View the difference between two commits.
git diff#View the difference between the working directory and the staging area.
git diff --cached#View the difference between the staging area and the most recent commit.
git reset HEAD <file>#Unstage a file, but dont alter the working directory or move the current branch.
git checkout <commit-id> <file>#Revert an individual file to match the specified commit without switching branches.
git config --global alias.<alias-name> <git-command>#Create a shortcut for a command and store it in the global configuration file.
Plumbing
git cat-file <type> <object-id>#Display the specified object, where <type> is one of commit, tree, blob, or tag.
git cat-file -t <object-id>#Output the type of the specified object.
git ls-tree <tree-id>#Display a pretty version of the specified tree object.
git gc#Perform a garbage collection on the object database.
git update-index [--add] <file>#Stage the specified file, using the optional --add flag to denote a new untracked file.
git write-tree#Generate a tree from the index and store it in the object database. Returns the ID of the new tree object.
git commit-tree <tree-id> -p <parent-id>#Create a new commit object from the given tree object and parent commit. Returns the ID of the new commit object.