git tips

記錄一些git小知識

push

force-with-lease

能夠在rebase後force, 同時避免覆蓋他人提交, 具體見 git push --helpnode

git push origin --force-with-lease
This option allows you to say that you expect the history you are updating is what you rebased and want to replace. If the remote ref still points at the commit you specified, you can be sure that no other people did anything to the ref. It is like taking a "lease" on the ref without explicitly locking it, and the remote ref is updated only if the "lease" is still valid.
--force-with-lease alone, without specifying the details, will protect all remote refs that are going to be updated by requiring their current value to be the same as the remote-tracking branch we have for them.

merge

查看分叉點

~/ejoy/battleship(etcd1) » git merge-base --fork-point master etcd1
489889ee3e6ab88f5be217590b9bcfab908227da

rebase

interactive rebase 時顯示做者和commit msg

git config --add rebase.instructionFormat "(%an <%ae>) %s"
git config --global rebase.instructionFormat "(%an <%ae>) %s"

clean

清理本地的untracked files

how-to-remove-local-untracked-files-from-the-current-git-working-treegit

# Print out the list of files which will be removed (dry run)
git clean -n
# Delete the files from the repository
git clean -f

conflict

選擇本身/他人的修改

choose-git-merge-strategy-for-specific-files-ours-mine-theirssegmentfault

git checkout --ours -- <paths>
git checkout --theirs -- <paths>

revert

revert ammend

剛剛amend

# Move the current head so that it's pointing at the old commit
# Leave the index intact for redoing the commit.
# HEAD@{1} gives you "the commit that HEAD pointed at before 
# it was moved to where it currently points at". Note that this is
# different from HEAD~1, which gives you "the commit that is the
# parent node of the commit that HEAD is currently pointing to."
git reset --soft HEAD@{1}

soft會保留提交, head@{1}即ammend以前的提交.ui

已經ammend許久

git log --reflog
git reset SHA1 --soft
相關文章
相關標籤/搜索