2023-10-22
Ifølge https://koukia.ca/rename-or-move-files-in-git-e7259bf5a0b7
Hvis du vil være sikker på at file history blir ivaretatt i en fil om du renamer den (eller flytter den), så må du bruke commando-linja og kjøre
git mv mycoolclass.cs myCoolClass.cs
eller
git mv layout/CardList common/List
Hvis du renamer direkte i editor-en, så kan du ikke være sikker på at git skjønner at det er samme fil.
Når du ivaretar git history så kan du bruke ting som git log -p --follow -- path/to/filename. Se gist: https://gist.github.com/paalss/7127b421ff7f3a862ae8d76c772aeb6a
Kommentarer:
Mulig det er unødvendig å bruke mv. Da jeg renamet og flyttet layout/CardList til common/List så skjønte git at disse to filene var 74% like.
git log -p --follow components/common/List/List.tsx funker fjell. Historikken strekker seg tilbake til før renamingen
2023-10-22
Links
2023-10-22
source /usr/share/bash-completion/completions/git
__git_complete gco _git_checkout
__git_complete gb _git_branch
__git_complete gbs _git_bisect
__git_complete ga _git_add
__git_complete gcmsg _git_commit
__git_complete gcs _git_commit
__git_complete gd _git_diff
__git_complete gl _git_pull
__git_complete gp _git_push
__git_complete gm _git_merge
2023-10-29
Færre antall branches i code completion suggestion når du skriver git checkout feat-[Tab].
Slett alle branches som ikke finnes på remote:
git fetch -p
(git fetch prune)
Også, sørg for å slette unødvendige tags
List tags
git tag
git tag -d tagName
2023-11-05
Eg. Search for "use-query-params" in package.json's git history
git grep use-query-params $(git rev-list --all -- package.json) -- package.json
As a function in .bashrc/.zshrc-file
filehistorysearch() {
git grep $1 $(git rev-list --all -- $2) -- $2
}
2024-05-20
git reflog
copy hash (ex: 56e2f8f)
git checkout main/develop
git merge 56e2f8f
2024-10-21
git ls-files -u | sed -n 's,3\t,0\t,p' | git update-index --index-info
git checkout-index -af
https://stackoverflow.com/questions/73388057/in-git-after-merging-some-files-i-want-to-accept-all-theirs-that-are-left-in?rq=3
2025-05-12
https://jvns.ca/blog/2023/11/06/rebasing-what-can-go-wrong-/
2025-08-11
Reverse apply changes from old commit
git checkout <commit-hash>
git log
git diff <previous-commit-hash> > diff.patch
git checkout <main-or-up-to-date-branch>
git apply diff.patch --reverse
Create new commit that revert last commit
git revert <last-commit-hash>
2025-10-16
<!--
git rebase -X theirs main
git rebase -X theirs develop -i
-->
git tag branch_before_rebase
git rebase -X theirs develop
- Manually compare current branch with
branch_before_rebase
- Correct whatever needs to be corrected
2025-10-31
git diff develop..$(git branch --show-current)
git branch --show-current is current branch
Lazygit
- Highlight main branch
- Shift w & hit enter
- highlight the branch you want to compare with
Webstorm
- GitToolBox?
https://useful-snippets.netlify.app/posts/webstorm-compare-with-branch/

VS Code
- Gitlens?
Neovim
- Diffview
2025-11-13
git restore --staged file-name.txt
2025-12-02
git checkout another-local-branch path/to/file.js
2025-12-02
git checkout HEAD^
git checkout HEAD@{1}
Go forward
List ancestry (later) commits
From HEAD (older commit) to main branch (up-to-date)
git log --reverse --ancestry-path HEAD^..main
2026-02-23
git reset --soft HEAD~1
2026-02-25
To activate pre-push, rename .git/hooks/pre-push.sample to .git/hooks/pre-push
Example script:
branch_name=$(git symbolic-ref HEAD 2>/dev/null)
echo "$branch_name"
if [ "$branch_name" != "refs/heads/min-branch" ]; then
echo "You can't push this branch."
exit 1
fi
exit 0
should work given that this command:
git symbolic-ref HEAD 2>/dev/null
gives: refs/heads/min-branch
and:
git symbolic-ref HEAD 2>/dev/null | cut -d"/" -f 3
gives min-branch