This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| snippets:git [2015/10/05 11:46] – allspark_cp | snippets:git [2022/06/28 10:32] (current) – allspark | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | # git push --force | + | # git |
| - | 1. git fetch | + | https:// |
| - | 1. git reset origin/master --hard | + | |
| + | https:// | ||
| + | |||
| + | ## git push --force | ||
| + | |||
| + | ``` | ||
| + | git fetch | ||
| + | git reset origin/ | ||
| + | ``` | ||
| + | |||
| + | ## remove last commit, but keep changes | ||
| + | |||
| + | ``` | ||
| + | git reset HEAD~ | ||
| + | ``` | ||
| + | |||
| + | ## tree on console | ||
| + | |||
| + | ``` | ||
| + | git config --global alias.tree "log --oneline --decorate --all --graph" | ||
| + | ``` | ||
| + | |||
| + | ```bash | ||
| + | #!/bin/bash | ||
| + | |||
| + | GIT_DIR=/ | ||
| + | WORK_DIR=/ | ||
| + | |||
| + | BRANCHES=(' | ||
| + | |||
| + | set -x | ||
| + | |||
| + | for i in " | ||
| + | do | ||
| + | git --git-dir=${GIT_DIR} --work-tree=${WORK_DIR} checkout ${i} | ||
| + | git --git-dir=${GIT_DIR} --work-tree=${WORK_DIR} rebase master | ||
| + | git --git-dir=${GIT_DIR} --work-tree=${WORK_DIR} push -f | ||
| + | |||
| + | done | ||
| + | |||
| + | git --git-dir=${GIT_DIR} --work-tree=${WORK_DIR} checkout master | ||
| + | |||
| + | ``` | ||
| + | |||
| + | ## ignore changes in tracked file | ||
| + | |||
| + | ``` | ||
| + | git update-index --assume-unchanged file | ||
| + | ``` | ||
| + | |||
| + | To undo and start tracking again: | ||
| + | |||
| + | ``` | ||
| + | git update-index --no-assume-unchanged [< | ||
| + | ``` | ||
| + | |||
| + | ## split directory to new repo | ||
| + | |||
| + | ``` | ||
| + | git filter-branch --prune-empty --subdirectory-filter FOLDER-NAME | ||
| + | ``` | ||
| + | |||
| + | ## show staged diff | ||
| + | |||
| + | ``` | ||
| + | git diff --cached | ||
| + | ``` | ||
| + | |||
| + | ## revert part of a commit | ||
| + | |||
| + | ``` | ||
| + | git revert -n $bad_commit | ||
| + | git reset HEAD . # Unstage the changes | ||
| + | git add --patch . # Add whatever changes you want | ||
| + | git commit | ||
| + | ``` | ||
| + | |||
| + | ## delete remote branch | ||
| + | |||
| + | ``` | ||
| + | git push origin --delete feature/ | ||
| + | ``` | ||