summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Lewis <mlewis@gitlab.com>2019-04-30 20:01:38 +0000
committerMike Lewis <mlewis@gitlab.com>2019-04-30 20:01:38 +0000
commitb214ce720b828483dd0cff9b77b6ebdefb4d3a75 (patch)
tree5013fcae01e485278334cbe99302aa49180faf3a
parente0736f9b43418718d09d59545ef40c00586552db (diff)
downloadgitlab-ce-b214ce720b828483dd0cff9b77b6ebdefb4d3a75.tar.gz
Update git-tricks md
-rw-r--r--doc/topics/git/git-tricks.md95
1 files changed, 62 insertions, 33 deletions
diff --git a/doc/topics/git/git-tricks.md b/doc/topics/git/git-tricks.md
index 7f93ed65426..622b8c906bf 100644
--- a/doc/topics/git/git-tricks.md
+++ b/doc/topics/git/git-tricks.md
@@ -5,83 +5,112 @@ handy when needed.
## bash
-### Add another url to a remote, so both urls get updated on every push
-git remote set-url --add <remote_name> <remote_url>
+### Add another URL to a remote, so both URLs get updated on each push
-### removes last commit and leaves the changes made in 'unstaged'
-git reset --soft HEAD^
+`git remote set-url --add <remote_name> <remote_url>`
-### unstages a certain number of commits (3 here) from HEAD
-git reset HEAD^3
+### Remove last commit and leave the changes in unstaged
-### unstages changes to a certain file to HEAD
-git reset <filename>
+`git reset --soft HEAD^`
-### reverts a file to what's in HEAD. REMOVES changes made.
+### Unstage a certain number of commits from HEAD
+
+For example, to unstage 3 commits
+
+`git reset HEAD^3`
+
+### Unstage changes to a certain file from HEAD
+
+`git reset <filename>`
+
+### Revert a file to HEAD state and remove changes
+
+```
git checkout <filename>
git reset --hard <filename>
+```
-### undo a previous commit. this does the opposite by creating a new commit
-git revert <commit-sha>
+### Undo a previous commit by creating a new replacement commit
-### create a new message for last commit
-git commit --amend
+`git revert <commit-sha>`
+
+### Create a new message for last commit
+
+`git commit --amend`
-### add a file to the last commit
+### Add a file to the last commit
+
+```
git add <filename>
git commit --amend
-# add --no-edit to NOT edit the commit message
+```
+
+add `--no-edit` to NOT edit the commit message
+
+### Stash changes
-### stash changes - both below are equivalent
-git stash save
-git stash
+`git stash save`
+or
+`git stash`
### unstash your changes
-git stash apply
+
+`git stash apply`
### discard your stashed changes
-git stash drop
+
+`git stash drop`
### apply and drop your stashed changes
-git stash pop
+
+`git stash pop`
### check the git history of a file
-git log -- <file>
-git log <file>
+
+```git log -- <file>
+git log <file>```
### find the tags that contain a particular SHA
-git tag --contains <sha>
+
+`git tag --contains <sha>`
### check the content of each change to a file
-gitk <file>
+
+`gitk <file>`
### check the content of each change to a file, follows it past file renames
-gitk --follow <file>
+
+`gitk --follow <file>`
## Debugging
### Use a custom SSH key for a git command
-GIT_SSH_COMMAND="ssh -i ~/.ssh/gitlabadmin" git <command>
+`GIT_SSH_COMMAND="ssh -i ~/.ssh/gitlabadmin" git <command>`
### Debug cloning
-GIT_SSH_COMMAND="ssh -vvv" git clone <git@url> # with SSH
-GIT_TRACE_PACKET=1 GIT_TRACE=2 GIT_CURL_VERBOSE=1 git clone <url> # with HTTPS
+`GIT_SSH_COMMAND="ssh -vvv" git clone <git@url>` with SSH
+`GIT_TRACE_PACKET=1 GIT_TRACE=2 GIT_CURL_VERBOSE=1 git clone <url>` with HTTPS
## Rebasing
-### Rebase your branch onto master.
-# the -i flag stands for 'interactive'
-git rebase -i master
+### Rebase your branch onto master
+
+The -i flag stands for 'interactive'
+
+`git rebase -i master`
### Continue the rebase if paused
-git rebase --continue
+
+`git rebase --continue`
### Additional rebasing tips
Rerere _reuses_ recorded solutions to the same problems when repeated
+
`git config --global rerere.enabled true`
Use the reference log (reflog) to show the log of reference changes to HEAD
+
`git reflog` \ No newline at end of file