git: Intermediate Concepts and Commands
					
						
							Created by: Steve Bass
							
							June, 2019 |
							stevebass.me
						
					
        
				
				
					$ git help
					
						- Your new best friend
 
						- On windows, opens a webpage version of the manual page of the command argument provided
 
						- Within a proper linux shell environment, prints the man page of the command argument provided
 
					
				
				
				
					$ git cherry-pick
					
						- Cherry picking is simply taking specific commits from git history and applying them onto a different branch
 
						- Arguments are the SHA-1 hashes associated with the commits desired
 
						- When multiple hashes are provided, they are applied to the current branch in order of left to right
 
					
				
				
					
						
(master)$ git log
  de34123f
  hi442ihl
  4jfl113n
(master)$ git checkout my-branch
(my-branch)$ git cherry-pick 4jfl113n de34123f
(my-branch)$ git log
  de34123f
  4jfl113n
						
					
					
					
					Source: ralfebert.de
				
				
					Cherry Picking: Pros/Cons
					
						
							
								Pros
								
									- Specific features can be escalated to other branches
 
								
							 
							
								Cons
								
									- New SHA-1 hash codes for each selected commit are applied in the destination branch
 
									- Its success is heavily dependent on the state of the branch of execution
 
								
							 
						 
					
				
				
				
					$ git mergetool
					
						
							
								- When downloaded and referenced in a .gitconfig, a merge tool will be invoked
 
								- Merge tools provide a better merge conflict resolution experience
 
							
						 
						
							.gitconfig entries:
							
								
[merge]
  tool = kdiff3
[mergetool "kdiff3"]
  path = /path/to/kdiff3.exe
  keepBackup = false
  trustExitCode = false
								
							
						 
					 
				
				
				
				
					$ git merge
					
						- When executed on a branch, will merge the argument branch into the currently checked out branch
 
					
				
				
				
					$ git rebase
					
						- Rebasing is exactly what it sounds like 😁
 
						- Interactive rebasing is a powerful method of keeping history clean
 
						
							
								- Provokes additional review of new commits by original author
 
								- Allows for squashing (consolidating) commits
 
							
						
					
				
				
					
						
(master)$ git pull
(master)$ git checkout my-branch
(my-branch)$ git log
  dj43j5k3  # not yet on master
(my-branch)$ git rebase -i master
# Enter interactive rebase session in text editor to pick/squash/delete dj43j5k3
						
					
					
						
					
				
				
				
					$ git revert
					
						Review:
					
					
						
							- Git commits are created as a git object stored within .git/objects whose contents are hashed into a checksum
 
						
						- Reverting backs out the changes of a specific commit
 
						- Reverting creates a "revert commit"
 
						
							
								- Revert commits can also be reverted, which re-introduces the reverted commit
 
							
						
					
				
				
				
					Deleting Sensitive Data
					
						- Legacy: git-filter-branch
 
						
						- Today: BFG
 
						
					
				
        
          Practice
          
            - 
              Take a look at the sister-repo: git-intermediate-practice
            
 
            - 
              It is pre-configured with branches whose history is set up to allow for practicing the commands covered by this deck. Simply follow the README's instructions to practice!
            
 
          
        
				
					Conclusion
					Be diligent about:
					
						- $ git help
 
						- Pulling early, and pulling often
 
						- Organizing changes into minimal, logical commits
 
						- Getting comfortable with merge tools
 
					
				
				
					Helpful Links
					
						- Atlassian's git cheat sheet - PDF Download
 
						- Atlassian article on Merging vs. Rebasing, and when each is appropriate
 
						- The entire Pro Git book by authors Scott Chacon and Ben Straub