Skip to content

Instantly share code, notes, and snippets.

@MKHyperlink
Last active February 1, 2021 10:12
Show Gist options
  • Save MKHyperlink/bcc00a4b10bf3da3f925f98d6ace7fc0 to your computer and use it in GitHub Desktop.
Save MKHyperlink/bcc00a4b10bf3da3f925f98d6ace7fc0 to your computer and use it in GitHub Desktop.
#============ git auto complete ==============
curl https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash > ~/.git-completion.sh
echo "" >> ~/.bash_profile
echo "# git completion" >> ~/.bash_profile
echo "[ -f ~/.git-completion.sh ] && . ~/.git-completion.sh" >> ~/.bash_profile
source ~/.bash_profile
#============ Beyond Compare ==============
Git 2.3 and newer
(Note: Use bc3 on the command line for BC version 4. Caused by git legacy support from Linux.)
Launch Beyond Compare, go to the Beyond Compare menu and run Install Command Line Tools.
Diff
In a terminal:
git config --global diff.tool bc3
To launch a diff using Beyond Compare, use the command: git difftool file.ext
Merge Pro only
In a terminal:
git config --global merge.tool bc3
git config --global mergetool.bc3.trustExitCode true
To launch a 3-way merge using Beyond Compare, use the command: git mergetool file.ext
#=========== .gitconfig =========================
[user]
email = mkhyperlink@gmail.com
name = mkhyperlink
[diff]
tool = bc3
[difftool "bc3"]
trustExitCode = true
[merge]
tool = bc3
[mergetool "bc3"]
trustExitCode = true
[color]
ui = true
[core]
excludesfile = /Users/mike/.gitignore_global
[mergetool]
keepBackup = false
#============ git diff/merge use beyond compare on macOS ==============
http://www.scootersoftware.com/support.php?zz=kb_vcs_osx
#============ git branch/folder compare ==============
git difftool [--dir-diff | -d] [--no-symlinks] [branch]
git difftool [branch] -- [folder] [branch] -- [folder]
#============ git submodule ==============
git submodule foreach git reset --hard
git submodule foreach --recursive git reset --hard
git submodule update --init --recursive
git submoduel sync
git submodule add https://github.com/<user>/rock rock
# search log with content
git log -g --grep " "
#============ git remote ==============
git remote show origin
git remote prune origin
# i:interactive, d:directory, f:force
git clean -ifd
# pull remote branch f:force merge
git branch -f remote_branch_name origin/remote_branch_name
git checkout remote_branch_name
# redo git rest
git reflog
#============ git stash 暫存目前變更 ============
git stash list
#套用 stash 的暫存至目前 branch (使用最後一次儲存的 stash)
git stash apply
#套用指定的 stash(配合 list 取得編號)
git stash apply stash@{0}
# 同 git log 使用方式
git stash show
git stash show -p
#============ git tag ============
#-a 標籤名稱,-m 標籤說明
git tag -a v1.4 -m 'my version 1.4' [commit]
git push origin v1.4
#============ git rollback ============
git reset --hard [commit]
git reset --hard origin/[remote branch] (Reset to remote branch)
#============ git pull/push 流程 ============
#On main branch "master"
1-1. git fetch origin master
1-2. git rebase
#or git pull
#switch to branch you want to push. ex. "features"
2-1. git rebase master
#if there are any cnfliction
2-2. git mergetool (我換成使用 beyond compare 當 merge 工具,預設是 git merge)
#Solved confliction
2-3. git add [files] #add merged files
2-4. git rebase --continue
#switch to main branch
3-1. git merge [branch]
3-2. git push origin master
#============ git diff ============
# diff by folder result
# In the Folder Compare, click the Rules toolbar button (referee icon). Go to the Handling tab. Check Follow symbolic links.
git difftool --dir-diff [branch/commit]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment