git

Table of Contents

1. Stash/Restore/Reset/Delete

  • Delete from history

    git filter-branch --index-filter 'git rm -rf --cached --ignore-unmatch path_to_file' HEAD
    
  • stash
git stash -- filename.ext # stash a singe file
  • Untracked files

    git clean -fdx # delete all untracked files
    git ls-files --others --exclude-standard # show all untracked files
    
  • Remove from added/staged

    git reset filename.txt # (older than git restore, use restore instead)
    git restore .
    git restore path/to/file/to/revert # for a specific file
    git restore --staged path/to/file/to/revert # for a specific file
    git rm --cached <file> # forget about a file that it is tracking
    

2. submodules

  • Pull latest changes of the submodules too
git pull --recurse-submodules --jobs=10

3. Random git commands

ls $(git diff master --name-only) # list all changed files
git log <commit_hash>..HEAD --reverse| awk '{print $1}' | paste -s -d ' '
git cat-file <object> # lets us inspect commit, tags, other stuff

3.1. Search

git log -G someFunc # search for someFunc in all of git history in same branch
git log --all -G someFunc # search for someFunc in all of git history in all branches
git log -S someFunc # changes in occurrence counts, similar to -G but better in some cases

4. Remote

git push <remote> -d <branch_name>

Created: 2024-07-16 Tue 16:44

Validate