Skip to main content

Git --CheetSheet=4

Interactive Rebase :

1. git rebase -i HEAD~4  #Interactive rebase to edit last 4 commits

2.
Plot :
You notice a critical error on your part. The commit where you wrote tests comes after the commit where you made the actual changes. Let's swap these 2 commits so that it looks like you wrote the tests first. Swap the 'Add tests' commit so that it comes before the 'Implement poodles' commit.


pick b3f1649 Add unicorn
pick 4b65a5a Add tests
pick f239187 Implement poodles
pick c3f863f Added a title to the homepage


3.Plot : As you're editing your commits, you notice that the commit that says 'Add tests' is a little vague, maybe you should change it to something more specific. Use the reword command to change the message of this commit.

pick b3f1649 Add unicorn
reword 4b65a5a Add tests to commit
pick f239187 Implement poodles
pick c3f863f Added a title to the homepage


4.Plot : You remember that the 'Add unicorn' commit also contains the testing changes. Since we have separate commits for adding tests for poodles it makes sense to split out the test changes into a separate commit. Tell git to stop at this commit so we can reorganize it a bit.

edit b3f1649 Add unicorn
pick 4b65a5a Added tests for poodles
pick f239187 Implement poodles
pick c3f863f Added a title to the homepage

5.Plot : After saving the interactive rebase text file, git has stopped at the 'Add unicorn' commit. The first thing we need to do is to reset back to the previous commit, so the changes in the most recent commit are back in the file and unstaged.

git reset HEAD~1

6.git rebase --continue

7.Plot :  You noticed another bug with those pesky poodles, so you've gone ahead and fixed it, making another commit in the process. Now you have 2 commits that both affect the poodles page. You should squash them into one commit to simplify your git logs.

pick b3f1649 Add unicorn
pick 4b65a5a Add tests
pick f239187 Implement poodles
squash c3f863f Add title to poodle page


8.  git stash #stash the present changes

9.  git stash list #get the list of stashes.

10. git stash apply #get the stash back

11. git stash drop #clean up the stash list.

12. git reset --hard #hard reset the last commit.

13. git stash pop #apply the stash and delete it in the stash list.

14. git stash --keep-index #stash only unstaged changes

15. git stash --include-untracked #stash also the untracked changes.

16. git stash list --list #stats on each listed files.

17. git stash show stash@{2} --patch #shows the expansion and details of second stash

18. git stash save "Added some message to stash" #lets you add name to the stash

19. git stash brach testbranch  #a new brach is created named "testbranch" from the stashed changes.

Pruning History :

1. git clone poodle first-one  #get the repo copied with another name, in this case "first-one"

2.git filter-branch --tree-filter 'git rm --cached --ignore-unmatch master_password.txt'

3.git filter-branch -f --tree-filter 'git rm --cached --ignore-unmatch master_username.txt'   #remove file from all of repo history

4.git filter-branch -f --prune-empty #remove the references of the deleted file.


Comments

Popular posts from this blog

ASCII to Decimal conversion

#include "msp430.h"                     ; #define controlled include file         NAME    main                    ; module name         PUBLIC  main                    ; make the main label vissible                                         ; outside this module         ORG     0FFFEh         DC16    init                    ; set reset vector to 'init' label         RSEG    CSTACK                  ; pre-declaration of segment         RSEG    CODE      ...

Event Sourcing with CQRS.

  The way event sourcing works with CQRS is to have  part of the application that models updates as writes to an event log or Kafka topic . This is paired with an event handler that subscribes to the Kafka topic, transforms the event (as required) and writes the materialized view to a read store.

Create One-Click Shutdown and Reboot Shortcuts

First, create a shortcut on your desktop by right-clicking on the desktop, choosing New, and then choosing Shortcut. The Create Shortcut Wizard appears. In the box asking for the location of the shortcut, type shutdown. After you create the shortcut, double-clicking on it will shut down your PC. But you can do much more with a shutdown shortcut than merely shut down your PC. You can add any combination of several switches to do extra duty, like this: shutdown -r -t 01 -c "Rebooting your PC" Double-clicking on that shortcut will reboot your PC after a one-second delay and display the message "Rebooting your PC." The shutdown command includes a variety of switches you can use to customize it. Table 1-3 lists all of them and describes their use. I use this technique to create two shutdown shortcuts on my desktop—one for turning off my PC, and one for rebooting. Here are the ones I use: shutdown -s -t 03 -c "Bye Bye m8!" shutdown -r -t 03 -c ...