git - jasper-zanjani/dotfiles GitHub Wiki
add ? branch ? checkout ? cherry-pick ? clean ? config ? log ? ls-files ? mv ? push ? rebase ? remote ? reset ? revert ? rm ? stash ?
Add file, located in $HOME to the git repo at $PATH
git --git-dir=$PATH.git --work-tree=$HOME add fileUpdate index to include all files in the working tree, including removals
git add -A
git add --no-ignore-removalStage all modifications in work-tree, including deletions
git add -uSee a list of branches. A "*" indicates that branch is checked out.
git branchDisplay the last commit for each branch
git branch -vDisplay branches that have not been merged
git branch --no-mergedDiscard unstaged uncommitted changes to file
git checkout -- fileSwitch to branch
git checkout branchApply a single, specific commit from another branch
git cherry-pick commitProvides a frontend to the INI formatted config files typically found within .git/config (or ~/.gitconfig when using --global)
Set up alias "br" for branch
git config --global alias.br branchEquivalent to:
[alias]
br = branchStore authentication details in a cache
git config --global credential.helper cacheEquivalent to
[credential]
helper = cacheShow commits between January 1 and January 5, 2016
git log --after="2016-01-01" --before="2016-01-05"See commits that are on {branch} but not on {master}
git log master..branchShow tracked files
git ls-filesShow tracked files, each line is terminated by a null byte
git ls-files -zShow tracked files that have been deleted
git ls-files --deletedMove or rename a tracked file
git mv fileTransfer data from local branch {master} to remote {origin}
git push -u origin masterTo add changes to a commit that is not the most recent, a rebase is necessary.
First stash the changes to be added, then initiate a rebase and mark the commit to be edited with edit or e.
Leave the other commits alone, save, and drop back to the stash.
Pop the stash (git stash pop), which will apply the changes stored in the most recent stash.
Now you can stage the changes and commit:
git commit --amend --no-editFinally, continue the rebase, rewriting the rest of the commits against the new one.
git rebase --continueCombine branches by replaying the changes made on one branch to another
git rebaseManage repositories whose branches you track
git remoteAdd remote repo
git remote add $REPO $URLDisplay URL of remote repo
git remote get-url $REPOSet url for existing repo
git remote set-url $URL $REPOUndo unstaged changes since last commit
git reset --hardReset master to state before last commit
git reset --hard HEAD~Remove (committed) changes in {commit}
git revert commitRemove tracked file from repo
git rm fileStash changes to work-tree
git stashView stashes in stash stack
git stash listApply changes in most recent stash
git stash applyApply changes in stash $STASH
git stash apply stash@$STASHRebase changes committed to branch onto
git checkout $BRANCH
git rebase $MASTERThis will rewind $BRANCH to the commit shared by the two branches, then applying all changes made subsequently to $MASTER.
git checkout <master>
git merge <branch>Now the history will appear as though all changes were made in series, when they were actually made in parallel on separate branches. Move the last commit to a new branch
git branch test # create a new branch with current HEAD
git reset --hard HEAD~ # reset master to before last commit
git checkout test # continue on new branchLine endings Git will automatically append CRLF endings on Windows. This setting can be displayed with the following command:
git config core.autocrlfIn order to disable this, adjust the setting
git config core.autocrlf falseSometimes many commits are made to resolve a single issue. These should be "squashed". To squash the last 4 commits:
git rebase -i HEAD~4This will open a text editor where you will have to select what to do with each of the 4 commits. Most recent commits are at the bottom, and at least the top (oldest) commit has to remain "pick" in order to squash the others. The repo will have to be force-pushed once these changes have been made.
git push --forceTo add changes to the most recent commit, stage changes as normal (including removals), but when committing use the --amend option. This will present an editor, allowing you to edit the commit message, if necessary. [6]
git add README.md
git commit --amend
To split up $COMMIT
git rebase -i "$COMMIT"^ # Start a rebase at the commit you want to splitMark the commit to be split with edit. Now reset state to the previous commit
git reset HEAD^The files are presented unstaged, and can be added to new commits as needed. Finally, finish the rebase
git rebase --continueProvides a curses-based browser that allows you to navigate the commits in the current branch.
It is essentially a wrapper around git log, and therefore accepts the same arguments that can be passed to it.
| Config file | Description |
|---|---|
| $HOME/.tigrc |
Browse the commit history for a single {file}
tig fileBrowse the commit history for a single {file}, filtering to a specific date range
tig --after="2017-01-01" --before="2018-05-16" -- README.mdFind who made a change toa file and why
tig blame fileBrowse stash
tig stashBrowse refs
tig refsNavigate the output of git grep
tig grep -i foo lib/BarPipe a list of commit IDs to tig
git rev-list --author=olaf HEAD | tig show --stdin