Skip to content

Instantly share code, notes, and snippets.

@nrninsane
Last active June 2, 2021 09:14
Show Gist options
  • Select an option

  • Save nrninsane/eb7d0fb69902072732d7a91e61d41f1a to your computer and use it in GitHub Desktop.

Select an option

Save nrninsane/eb7d0fb69902072732d7a91e61d41f1a to your computer and use it in GitHub Desktop.

Revisions

  1. nrninsane revised this gist Jun 2, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion splitting up a commit.md
    Original file line number Diff line number Diff line change
    @@ -15,7 +15,7 @@ git stash save "split this up into multiple commits"
    - ```git stash apply```
    - modify lines,
    - git add,
    - git commit (first one has to be ```--amend```!)
    - git commit

    3. get back the original state of the rebase step
    ```
  2. nrninsane revised this gist Apr 13, 2021. No changes.
  3. nrninsane revised this gist Apr 13, 2021. 1 changed file with 10 additions and 0 deletions.
    10 changes: 10 additions & 0 deletions git-log.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    from https://coderwall.com/p/euwpig/a-better-git-log

    configure
    ```bash
    git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"
    ```

    usages:
    - `git lg`
    - `git lg -p` to see line changes
  4. nrninsane revised this gist Oct 8, 2020. 1 changed file with 5 additions and 0 deletions.
    5 changes: 5 additions & 0 deletions dangling commits and cherry-picking.md
    Original file line number Diff line number Diff line change
    @@ -7,3 +7,8 @@ git reflog
    ```
    git cherry-pick <hash>
    ```

    - to cherry-pick without automatically committing
    ```
    git chery-pick -n <hash>
    ```
  5. nrninsane revised this gist Oct 8, 2020. 1 changed file with 9 additions and 0 deletions.
    9 changes: 9 additions & 0 deletions dangling commits and cherry-picking.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,9 @@
    - to find recent dangling commit
    ```
    git reflog
    ```

    - this dangling commit can be inserted back
    ```
    git cherry-pick <hash>
    ```
  6. nrninsane revised this gist Sep 14, 2020. 1 changed file with 7 additions and 2 deletions.
    9 changes: 7 additions & 2 deletions splitting up a commit.md
    Original file line number Diff line number Diff line change
    @@ -1,13 +1,18 @@
    Tip: practice this on a throwaway project to get a better grasp.

    0. create a backup
    ```
    git branch backup-in-case-of-screwup
    ```

    1. to split up the commit of current rebase step
    ```
    git reset HEAD^
    git stash save "<myStash>"
    git stash save "split this up into multiple commits"
    ```

    2. make the changes
    - ```git stash apply <myStash>```
    - ```git stash apply```
    - modify lines,
    - git add,
    - git commit (first one has to be ```--amend```!)
  7. nrninsane revised this gist Sep 14, 2020. 1 changed file with 6 additions and 4 deletions.
    10 changes: 6 additions & 4 deletions splitting up a commit.md
    Original file line number Diff line number Diff line change
    @@ -2,13 +2,15 @@ Tip: practice this on a throwaway project to get a better grasp.

    1. to split up the commit of current rebase step
    ```
    git stash save "<myStash>"
    git reset HEAD^
    git stash save "<myStash>"
    ```

    1. make the changes
    ```git stash apply <myStash>```
    modify lines, git add, git commit
    2. make the changes
    - ```git stash apply <myStash>```
    - modify lines,
    - git add,
    - git commit (first one has to be ```--amend```!)

    3. get back the original state of the rebase step
    ```
  8. nrninsane revised this gist Sep 11, 2020. No changes.
  9. nrninsane revised this gist Sep 11, 2020. 4 changed files with 60 additions and 70 deletions.
    18 changes: 18 additions & 0 deletions basic rebase.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    Note: only rebase local branches, **NEVER REBASE A REMOTE BRANCH**.

    1. create backup to preserve original commit tree
    ```
    git branch myBackup
    ```

    2. get list of commits and their SHA
    ```
    git --no-pager log --oneline
    ```

    3. start interactive rebase on targetSHA
    ```
    git rebase -i <targetSHA>^
    ```

    4. determine what to do with each commit & continue: keep, edit, etc. (git will show you the options)
    70 changes: 0 additions & 70 deletions git.md
    Original file line number Diff line number Diff line change
    @@ -1,70 +0,0 @@
    # Stashing

    Most of it is straightforward

    - to include untracked files
    ```
    git stash save --include-untracked "<myDescription>"
    ```

    - to include everything, even files/folders in .gitignore
    ```
    git stash --all "<myDescription>"
    ```

    # Basic rebasing

    Note: only rebase local branches, **NEVER REBASE A REMOTE BRANCH**.

    1. create backup to preserve original commit tree
    ```
    git branch myBackup
    ```

    2. get list of commits and their SHA
    ```
    git --no-pager log --oneline
    ```

    3. start interactive rebase on targetSHA
    ```
    git rebase -i <targetSHA>^
    ```

    4. determine what to do with each commit & continue: keep, edit, etc. (git will show you the options)

    ## Splitting up a commit

    Tip: practice this on a throwaway project to get a better grasp.

    1. to split up the commit of current rebase step
    ```
    git stash save "<myStash>"
    git reset HEAD^
    ```

    1. make the changes
    ```git stash apply <myStash>```
    modify lines, git add, git commit

    3. get back the original state of the rebase step
    ```
    git stash apply <myStash>
    ```

    4. repeat until nothing to commit

    5. if you are done with the current rebase step
    ```
    git rebase --continue
    ```

    **if you want to abort rebase**
    ```
    git rebase --abort
    ```

    **if rebase finished and it was not what you wanted**
    ```
    git reset myBackup --hard
    ```
    33 changes: 33 additions & 0 deletions splitting up a commit.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,33 @@
    Tip: practice this on a throwaway project to get a better grasp.

    1. to split up the commit of current rebase step
    ```
    git stash save "<myStash>"
    git reset HEAD^
    ```

    1. make the changes
    ```git stash apply <myStash>```
    modify lines, git add, git commit

    3. get back the original state of the rebase step
    ```
    git stash apply <myStash>
    ```

    4. repeat until nothing to commit

    5. if you are done with the current rebase step
    ```
    git rebase --continue
    ```

    **if you want to abort rebase**
    ```
    git rebase --abort
    ```

    **if rebase finished and it was not what you wanted**
    ```
    git reset myBackup --hard
    ```
    9 changes: 9 additions & 0 deletions stashing.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,9 @@
    - to include untracked files
    ```
    git stash save --include-untracked "<myDescription>"
    ```

    - to include everything, even files/folders in .gitignore
    ```
    git stash --all "<myDescription>"
    ```
  10. nrninsane revised this gist Aug 3, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion git.md
    Original file line number Diff line number Diff line change
    @@ -39,7 +39,7 @@ Tip: practice this on a throwaway project to get a better grasp.

    1. to split up the commit of current rebase step
    ```
    git stash save myStash
    git stash save "<myStash>"
    git reset HEAD^
    ```

  11. nrninsane revised this gist Aug 3, 2020. 1 changed file with 27 additions and 9 deletions.
    36 changes: 27 additions & 9 deletions git.md
    Original file line number Diff line number Diff line change
    @@ -3,23 +3,33 @@
    Most of it is straightforward

    - to include untracked files
    ```git stash save --include-untracked "<myDescription>"```
    ```
    git stash save --include-untracked "<myDescription>"
    ```

    - to include everything, even files/folders in .gitignore
    ```git stash --all "<myDescription>"```
    ```
    git stash --all "<myDescription>"
    ```

    # Basic rebasing

    Note: only rebase local branches, **NEVER REBASE A REMOTE BRANCH**.

    1. create backup to preserve original commit tree
    ```git branch myBackup```
    ```
    git branch myBackup
    ```

    2. get list of commits and their SHA
    ```git --no-pager log --oneline```
    ```
    git --no-pager log --oneline
    ```

    3. start interactive rebase on targetSHA
    ```git rebase -i <targetSHA>^```
    ```
    git rebase -i <targetSHA>^
    ```

    4. determine what to do with each commit & continue: keep, edit, etc. (git will show you the options)

    @@ -38,15 +48,23 @@ git reset HEAD^
    modify lines, git add, git commit

    3. get back the original state of the rebase step
    ```git stash apply <myStash>```
    ```
    git stash apply <myStash>
    ```

    4. repeat until nothing to commit

    5. if you are done with the current rebase step
    ```git rebase --continue```
    ```
    git rebase --continue
    ```

    **if you want to abort rebase**
    ```git rebase --abort```
    ```
    git rebase --abort
    ```

    **if rebase finished and it was not what you wanted**
    ```git reset myBackup --hard```
    ```
    git reset myBackup --hard
    ```
  12. nrninsane revised this gist Aug 3, 2020. 1 changed file with 10 additions and 10 deletions.
    20 changes: 10 additions & 10 deletions git.md
    Original file line number Diff line number Diff line change
    @@ -3,23 +3,23 @@
    Most of it is straightforward

    - to include untracked files
    `git stash save --include-untracked "<myDescription>"`
    ```git stash save --include-untracked "<myDescription>"```

    - to include everything, even files/folders in .gitignore
    `git stash --all "<myDescription>"`
    ```git stash --all "<myDescription>"```

    # Basic rebasing

    Note: only rebase local branches, **NEVER REBASE A REMOTE BRANCH**.

    1. create backup to preserve original commit tree
    `git branch myBackup`
    ```git branch myBackup```

    2. get list of commits and their SHA
    `git --no-pager log --oneline`
    ```git --no-pager log --oneline```

    3. start interactive rebase on targetSHA
    `git rebase -i <targetSHA>^`
    ```git rebase -i <targetSHA>^```

    4. determine what to do with each commit & continue: keep, edit, etc. (git will show you the options)

    @@ -34,19 +34,19 @@ git reset HEAD^
    ```

    1. make the changes
    `git stash apply <myStash>`
    ```git stash apply <myStash>```
    modify lines, git add, git commit

    3. get back the original state of the rebase step
    `git stash apply <myStash>`
    ```git stash apply <myStash>```

    4. repeat until nothing to commit

    5. if you are done with the current rebase step
    `git rebase --continue`
    ```git rebase --continue```

    **if you want to abort rebase**
    `git rebase --abort`
    ```git rebase --abort```

    **if rebase finished and it was not what you wanted**
    `git reset myBackup --hard`
    ```git reset myBackup --hard```
  13. nrninsane revised this gist Aug 3, 2020. 2 changed files with 52 additions and 52 deletions.
    52 changes: 0 additions & 52 deletions git.commands
    Original file line number Diff line number Diff line change
    @@ -1,52 +0,0 @@
    NOTE: ONLY REBASE A LOCAL BRANCH, **NEVER REBASE A REMOTE BRANCH**

    ##########################################
    # NOTE #
    ##########################################
    # #
    # ONLY REBASE A LOCAL BRANCH #
    # NEVER EVER EVER REBASE A REMOTE BRANCH #
    # #
    ##########################################

    # create backup to preserve original commit tree
    git branch myBackup

    # get list of commits and their SHA
    git --no-pager log --oneline

    # start interactive rebase on targetSHA
    git rebase -i targetSHA^

    # determine what to do with each commit & continue
    # keep, edit, etc. (git will show you the options)

    ## if you want to split up the commit of current rebase step
    git stash save myStash
    git reset HEAD^

    ### make the changes
    git stash apply myStash
    ### modify lines, git add, git commit

    ### get back the original state of the rebase step
    git stash apply myStash

    ### repeat until nothing to commit
    ### (go to line 16)

    ## if you are done with the current rebase step
    git rebase --continue

    ## if you want to abort rebase
    git rebase --abort

    #if rebase finished and it was not what you wanted
    git reset myBackup --hard

    ################
    # Tip:
    # Practice this on some nonsensical files
    # to get a sense for this process


    52 changes: 52 additions & 0 deletions git.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,52 @@
    # Stashing

    Most of it is straightforward

    - to include untracked files
    `git stash save --include-untracked "<myDescription>"`

    - to include everything, even files/folders in .gitignore
    `git stash --all "<myDescription>"`

    # Basic rebasing

    Note: only rebase local branches, **NEVER REBASE A REMOTE BRANCH**.

    1. create backup to preserve original commit tree
    `git branch myBackup`

    2. get list of commits and their SHA
    `git --no-pager log --oneline`

    3. start interactive rebase on targetSHA
    `git rebase -i <targetSHA>^`

    4. determine what to do with each commit & continue: keep, edit, etc. (git will show you the options)

    ## Splitting up a commit

    Tip: practice this on a throwaway project to get a better grasp.

    1. to split up the commit of current rebase step
    ```
    git stash save myStash
    git reset HEAD^
    ```

    1. make the changes
    `git stash apply <myStash>`
    modify lines, git add, git commit

    3. get back the original state of the rebase step
    `git stash apply <myStash>`

    4. repeat until nothing to commit

    5. if you are done with the current rebase step
    `git rebase --continue`

    **if you want to abort rebase**
    `git rebase --abort`

    **if rebase finished and it was not what you wanted**
    `git reset myBackup --hard`
  14. nrninsane revised this gist Aug 3, 2020. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions git.commands
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,5 @@
    NOTE: ONLY REBASE A LOCAL BRANCH, **NEVER REBASE A REMOTE BRANCH**

    ##########################################
    # NOTE #
    ##########################################
  15. nrninsane revised this gist Mar 15, 2020. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions git.commands
    Original file line number Diff line number Diff line change
    @@ -24,6 +24,7 @@ git stash save myStash
    git reset HEAD^

    ### make the changes
    git stash apply myStash
    ### modify lines, git add, git commit

    ### get back the original state of the rebase step
  16. nrninsane revised this gist Mar 15, 2020. No changes.
  17. nrninsane revised this gist Mar 15, 2020. 1 changed file with 8 additions and 8 deletions.
    16 changes: 8 additions & 8 deletions git.commands
    Original file line number Diff line number Diff line change
    @@ -1,11 +1,11 @@
    ##############################################
    # NOTE #
    ##############################################
    # #
    # ONLY REBASE ON A LOCAL BRANCH #
    # NEVER EVER EVER DO THIS ON A REMOTE BRANCH #
    # #
    ##############################################
    ##########################################
    # NOTE #
    ##########################################
    # #
    # ONLY REBASE A LOCAL BRANCH #
    # NEVER EVER EVER REBASE A REMOTE BRANCH #
    # #
    ##########################################

    # create backup to preserve original commit tree
    git branch myBackup
  18. nrninsane revised this gist Mar 15, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion git.commands
    Original file line number Diff line number Diff line change
    @@ -10,7 +10,7 @@
    # create backup to preserve original commit tree
    git branch myBackup

    # get list of commits
    # get list of commits and their SHA
    git --no-pager log --oneline

    # start interactive rebase on targetSHA
  19. nrninsane renamed this gist Mar 15, 2020. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  20. nrninsane renamed this gist Mar 15, 2020. 1 changed file with 4 additions and 3 deletions.
    7 changes: 4 additions & 3 deletions git commands → commands.git
    Original file line number Diff line number Diff line change
    @@ -41,8 +41,9 @@ git rebase --abort
    #if rebase finished and it was not what you wanted
    git reset myBackup --hard




    ################
    # Tip:
    # Practice this on some nonsensical files
    # to get a sense for this process


  21. nrninsane created this gist Mar 15, 2020.
    48 changes: 48 additions & 0 deletions git commands
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,48 @@
    ##############################################
    # NOTE #
    ##############################################
    # #
    # ONLY REBASE ON A LOCAL BRANCH #
    # NEVER EVER EVER DO THIS ON A REMOTE BRANCH #
    # #
    ##############################################

    # create backup to preserve original commit tree
    git branch myBackup

    # get list of commits
    git --no-pager log --oneline

    # start interactive rebase on targetSHA
    git rebase -i targetSHA^

    # determine what to do with each commit & continue
    # keep, edit, etc. (git will show you the options)

    ## if you want to split up the commit of current rebase step
    git stash save myStash
    git reset HEAD^

    ### make the changes
    ### modify lines, git add, git commit

    ### get back the original state of the rebase step
    git stash apply myStash

    ### repeat until nothing to commit
    ### (go to line 16)

    ## if you are done with the current rebase step
    git rebase --continue

    ## if you want to abort rebase
    git rebase --abort

    #if rebase finished and it was not what you wanted
    git reset myBackup --hard