This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| cheatsheet:git [2023/02/14 08:00] – created kamaradski | cheatsheet:git [2023/07/24 08:46] (current) – [other common commands] kamaradski | ||
|---|---|---|---|
| Line 17: | Line 17: | ||
| </ | </ | ||
| + | |||
| + | |||
| + | ===== revert to a previous commit (already pushed) ===== | ||
| + | |||
| + | <code bash> | ||
| + | git reset --hard < | ||
| + | </ | ||
| + | |||
| + | |||
| + | ===== git reset details ===== | ||
| + | |||
| + | git reset [< | ||
| + | |||
| + | * [< | ||
| + | * [< | ||
| + | |||
| + | Some possible options: | ||
| + | < | ||
| + | --hard: Reset the repository to the specified commit and discard all changes in the working tree. | ||
| + | |||
| + | --soft: Reset the repository to the specified commit, but keep changes in the working tree. | ||
| + | |||
| + | --mixed (default): Reset the repository to the specified commit, but keep changes in the index (staging area). | ||
| + | |||
| + | --merge: Reset the repository to the specified commit and keep changes that have been made in the working tree. | ||
| + | |||
| + | --keep: Keep changes in both the working tree and the index (staging area). | ||
| + | </ | ||
| + | |||
| + | |||
| + | ===== Use git stash to move code between branches ===== | ||
| + | |||
| + | A common use case that I use git stash for is when I make changes in the wrong branch that are bigger than just a few lines and thus not so easy to copy/paste into the next branch. | ||
| + | |||
| + | Here is how I do it: | ||
| + | |||
| + | < | ||
| + | git stash // stash your changes | ||
| + | git checkout feature_branch // Navigate to your feature branch (or create and checkout a new branch: git checkout -b feature_branch | ||
| + | git stash apply // apply the stashed changes | ||
| + | git add . | ||
| + | git commit -m "Your commit message here" | ||
| + | git stash drop // delete the stash in case yuo no longer need it | ||
| + | </ | ||
| + | |||
| + | |||
| + | ===== other common commands ===== | ||
| + | |||
| + | * '' | ||
| + | * '' | ||
| + | * '' | ||
| + | * '' | ||
| + | * '' | ||
| + | * '' | ||
| + | * '' | ||
| + | * '' | ||
| + | * '' | ||
| + | * '' | ||
| + | * '' | ||
| + | * '' | ||
| + | * '' | ||
| + | * '' | ||
| + | * '' | ||
| + | * '' | ||
| + | * '' | ||
| + | |||
| + | ===== .git/config ===== | ||
| + | |||
| + | Random stuff one can use in their git config file: ~/ | ||
| + | |||
| + | ==== User details ==== | ||
| + | |||
| + | < | ||
| + | [user] | ||
| + | email = [email protected] | ||
| + | name = username | ||
| + | </ | ||
| + | |||
| + | You can add this manually, or use the cli commands to populate the file with this information, | ||
| + | |||
| + | <code bash> | ||
| + | git config user.email " | ||
| + | git config user.name " | ||
| + | </ | ||
| + | |||
| + | ==== Aliases ==== | ||
| + | |||
| + | Setting up some short-cut commands for frequently used commands | ||
| + | |||
| + | < | ||
| + | [alias] | ||
| + | st = status | ||
| + | ci = commit | ||
| + | br = branch | ||
| + | co = checkout | ||
| + | df = diff | ||
| + | lg = log -p | ||
| + | lol = log --graph --decorate --pretty=oneline --abbrev-commit | ||
| + | kama = log --graph --pretty=format: | ||
| + | ls = ls-files | ||
| + | </ | ||
| + | |||
| + | |||
| + | ==== Formatting ==== | ||
| + | |||
| + | Funky colors | ||
| + | |||
| + | < | ||
| + | [color] | ||
| + | ui = auto | ||
| + | [color " | ||
| + | current = yellow reverse | ||
| + | local = yellow | ||
| + | remote = green | ||
| + | [color " | ||
| + | meta = yellow bold | ||
| + | frag = magenta bold | ||
| + | old = red bold | ||
| + | new = green bold | ||
| + | whitespace = red reverse | ||
| + | [color " | ||
| + | added = yellow | ||
| + | changed = green | ||
| + | untracked = cyan | ||
| + | </ | ||
| + | |||