meta data for this page
  •  

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
git:rewrite [2022/02/24 14:50] niziakgit:rewrite [2024/04/04 11:47] (current) niziak
Line 1: Line 1:
 ====== Rewrite history ====== ====== Rewrite history ======
 +
 +====== change initial commit ======
 +
 +<code bash>
 +git rebase -i --root
 +</code>
 +
 +====== reformat code in commits ======
 +
 +===== git rebase =====
 +
 +<code bash>
 +git rebase main -x 'make clang-reformat && git commit --amend'
 +</code>
 +
 +===== git-filter-repo =====
 +
 +<code bash>
 +wget https://raw.githubusercontent.com/newren/git-filter-repo/main/contrib/filter-repo-demos/lint-history
 +chmod +x lint-history
 +</code>
 +Apply patch from https://github.com/newren/git-filter-repo/issues/552
 +
 +<code bash>
 +./lint-history \
 +  --refs main..feeat-clang2 \
 +  --relevant 'return filename.endswith(b".c") or filename.endswith(b".h")' \
 +  clang-format-16 -i
 +</code>
 +
 +====== reword commits ======
 +
 +[[https://stackoverflow.com/questions/38233988/automatically-reword-all-rebased-commits|Automatically reword all rebased commits]]
 +
 +Following will automatically execute default editor for every commit:
 +<code bash>
 +git rebase origin/master -x 'git commit --amend'
 +</code>
  
 ====== Remove files from history (rewriting) ===== ====== Remove files from history (rewriting) =====
Line 21: Line 59:
  
 <code bash>git filter-repo --path-rename 'MYDIR/:'</code> <code bash>git filter-repo --path-rename 'MYDIR/:'</code>
 +
 +
 +====== Move from root to subdir ======
 +
 +<code bash>git filter-repo --path-rename ':app/'</code>
  
 ====== apply dos2unix ====== ====== apply dos2unix ======