<commit_before>#+TITLE: Joegle - Git Notes

See /‡ README/ section (bottom) for install notes

* Setup checklist
  + [ ] Place key in github
  + [ ] git lol
  + [ ] https://github.com/kamranahmedse/git-standup

* Basics
  + init a repo
    : git init
  + [[https://steindom.com/articles/add-empty-directory-git-repository][Add empty folder]]
    + Add .gitignore to folder with:
      #+BEGIN_SRC 
      *
      !.gitignore
      #+END_SRC
  + Unstage files
    : git reset <filePath>

** Config
   + List git aliases
     : git config --get-regexp alias
   + git lol alias
     : git config --global --add alias.lol "log --graph --decorate --pretty=oneline --abbrev-commit --all"

* Fixing  
  + Remove every line from history matching sed
    : git filter-branch --tree-filter 'sed -i "/sensitive information/ d" filename' -- --all
    + if you know the first commit
      : git filter-branch --tree-filter 'sed -i "/sensitive information/ d" filename' <commit>..HEAD
  + Remove every line from history that has word
    : git filter-branch --tree-filter "find . -type f -exec sed -i -e '/$*word/d' {} \;"
  + change password in every commit to new string
    :  git filter-branch --tree-filter "find . -type f -exec sed -i -e 's/originalpassword/newpassword/g' {} \;"
  + check for data
    : git filter-branch --tree-filter "grep -r originalpassword * || true"
  + remove file from history
    : git filter-branch -f --tree-filter 'rm -f full/path/file.js' HEAD
  + Backs ups are in .git/refs/original and can be removed (just one or all refs)
    : git update-ref -d refs/original/refs/heads/master
    : git for-each-ref --format="%(refname)" refs/original/ | xargs -n 1 git update-ref -d
  + Reattach head at point
    : git checkout <sha>
    : git branch my-new-branch -f

* Mutating
  + Pull versions of files from a branch
    : git checkout branch path path path
  + Add a file you forgot in the last commit
    : git add file-that-i-forgot.txt
    : git commit --amend --no-edit
  + Put a commit "on top" of current point
    : git rebase -i commit

* Remotes
  + change remote to ssh so that it doesnt ask for password
    : git remote set-url origin  <EMAIL>:joegle/git-notes.git
    + Stored in ~.git/config/~
  + View existing remotes
    : git remote -v

* ‡ README 

** Todo
   + [ ] bash completion
   + [ ] git prompt
   + [ ] git so fancy
   + [ ] add keys directions
   + [ ] https://github.com/git-tips/tips<commit_msg>more notes<commit_after>#+TITLE: Joegle - Git Notes

See /‡ README/ section (bottom) for install notes

* Inbox
  + [ ] https://github.com/kamranahmedse/git-standup

* Setup checklist
  + [ ] Place key in github
  + [ ] git lol

* Comparing / Diff
  + Diff what is staged
    : git diff --staged
  + 

* Basics
  + init a repo
    : git init
  + [[https://steindom.com/articles/add-empty-directory-git-repository][Add empty folder]]
    + Add .gitignore to folder with:
      #+BEGIN_SRC 
      *
      !.gitignore
      #+END_SRC
  + Unstage files
    : git reset <filePath>

** Config
   + List git aliases
     : git config --get-regexp alias
   + git lol alias
     : git config --global --add alias.lol "log --graph --decorate --pretty=oneline --abbrev-commit --all"

* Branching
  + create branch
    : git branch <branch>
  + delete branch
    : git branch -d <branch>
  + push branch and remember destination so you can just do 'git push' next time
    : git push -u origin <branch>

* Fixing  
  + Remove every line from history matching sed
    : git filter-branch --tree-filter 'sed -i "/sensitive information/ d" filename' -- --all
    + if you know the first commit
      : git filter-branch --tree-filter 'sed -i "/sensitive information/ d" filename' <commit>..HEAD
  + Remove every line from history that has word
    : git filter-branch --tree-filter "find . -type f -exec sed -i -e '/$*word/d' {} \;"
  + change password in every commit to new string
    :  git filter-branch --tree-filter "find . -type f -exec sed -i -e 's/originalpassword/newpassword/g' {} \;"
  + check for data
    : git filter-branch --tree-filter "grep -r originalpassword * || true"
  + remove file from history
    : git filter-branch -f --tree-filter 'rm -f full/path/file.js' HEAD
  + Backs ups are in .git/refs/original and can be removed (just one or all refs)
    : git update-ref -d refs/original/refs/heads/master
    : git for-each-ref --format="%(refname)" refs/original/ | xargs -n 1 git update-ref -d
  + Reattach head at point
    : git checkout <sha>
    : git branch my-new-branch -f

* Mutating
  + Pull versions of files from a branch
    : git checkout branch -- path path path
  + Add a file you forgot in the last commit
    : git add file-that-i-forgot.txt
    : git commit --amend --no-edit
  + Put a commit "on top" of current point
    : git rebase -i commit
  + delete file from git and disk
    : git rm path

* Remotes
  + change remote to ssh so that it doesnt ask for password
    : git remote set-url origin  <EMAIL>@github.com:joegle/git-notes.git
    + Stored in ~.git/config/~
  + View existing remotes
    : git remote -v

* ‡ README 

** Todo
   + [ ] bash completion
   + [ ] git prompt
   + [ ] git so fancy
   + [ ] add keys directions
   + [ ] https://github.com/git-tips/tips

{'fraction_non_alphanumeric': 0.11978670729384878, 'fraction_numerical': 0.00038087983241287375, 'mean_word_length': 2.4804506295559974, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 14, 'https://': 6, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5055685', 'n_tokens_mistral': 1734, 'n_tokens_neox': 1683, 'n_words': 610}