Tuesday, February 6, 2018

trying to get used to Git command line commands

git add .
git commit -m "This is my commit note"
git checkout master
git rebase -pull source master
git pull --rebase source master
git checkout myLocalBranch
git rebase master

 
 

Above we commit locally, switch to the master branch, rebase it (meaning that we bring into our copy of the master branch what is current in source control, getting commits there to play nicely with our own changes hopefully), switch back to our branch, and then suck in the master changes there. Checkout code to a new branch with:

git checkout -b whateverYouWant

 
 

This shows you a textual dump of all of the commit details in your branch:

git reflog

 
 

You'll see a history of commits such as HEAD{0} and HEAD{1} and this...

git reset --hard HEAD{0}

 
 

Will fall back to that particular commit. While

git reset --hard

 
 

...goes back to the commit that was current when you branched. Both of these are just affecting your local stuff. To update source control you would have to turn around and commit the local changes that now have the rollback. By the way this...

git reset --soft

 
 

...does the same thing as the hard reset but leaves all of the commits between the point to fall back to and point fallen back from as one big local change set that is uncommitted. It should be that if you branch, commit once, and then do a soft rollback without specifying a change set that what you will end up locally will be exactly equivalent to what is in source control anyways which is something that I found confusing until I could imagine other permutations of this.

git commit -i

 
 

This brings up the vi text editor (the name comes from the vi in "visual" not the Roman number 6) and allows for "cherry picking" what commits you wish to keep or drop. The i is for "interactive" in this madness.

 
 

Addendum 2/21/2018: The seven steps at the top of this blog post should really be the nine step below. Note that between steps six and seven one should clean up merge conflicts.

  1. git add .
  2. git commit -m "This is my commit note"
  3. git checkout master
  4. git pull --rebase source master
  5. git checkout myLocalBranch
  6. git rebase master
  7. git add .
  8. git rebase --continue
  9. git push origin myLocalBranch

 
 

Addendum 2/22/2018: Moreover...

git push origin myLocalBranch -f

 
 

...will force an update to your branch even if Git complains about the heads being out of sync and...

git rebase --abort

 
 

...lets you roll back changes made between step six and seven! Git, the name, is British slang for a person who is a tool or a jackass.

 
 

Addendum 1/9/2020: 4 above should just be: git pull --rebase master ...without the rest of it all.

 
 

Addendum 1/10/2020: 4 above should just be: git pull ...without the rest of it all. The addendum comment from yesterday is just wrong.

No comments:

Post a Comment