Git

Rebase and squash

Git commit messages

Link on ssh passwords

Markdown xxx cross out text in gitlab

Combine last 2 commits

</pre>
<pre><code>git rebase -i HEAD~3</code></pre>
<pre>

Misc

git reflog // find any commit
git reset file// unstage an added file

Commands

git rebase -i SHA (squash)
git remote prune origin (prune remotes)
git checkout --ours / --theirs path/file.txt
git commit  multi line commit message
git pull origin master
git checkout -b
git branch -D
git log --oneline
git shortlog

Revert all changes

git clean -df
git checkout -- .

git bisect

git bisect lets you walk forward and backwards in time, automatically checking out branches, and let you isolate something that broke the build. You bisect, run tests, and then say bisect good or bad. git automatically increments binary forward / backward. Then when you find offending commit you compare with head for diff.

Clean master

git bisect start
git bisect bad
git log (pick a suspect commit i.e e576341668478ec71d5e642bb63d9ada57785878)
git checkout e576341668478ec71d5e642bb63d9ada57785878 // check it out
git bisect good         // keep bisecting until you come to the bad commit
git bisect good
git bisect bad         // when you find the bad commit, mark it bad
git bisect good        // then bisect again to get the previous good commit

Note the output. It tells you where the first bad commit is. Note it and check it out. You are now on the bad commit. Compare this commit with the previous to note the differences.

git checkout 39ff0ffe5114a6a9011dd28ebe3ac3bdc92163e0
git diff HEAD~1

Screen Shot 2019-10-30 at 10.16.43 AM

You can copy this output into the paste board to save. Then checkout the previous version that works (a good one) and manual copy in the changes one at a time until you find the source of the break.

git diff HEAD~1 | pbcopy
git checkout HEAD~1

To stop:

git bisect reset

How to checkout someone else’s remote branch

git fetch
git checkout (remote branch name)

or

git remote add joe git@ghe.xxx.net:joe/library.git
git fetch joe player_state_notifications
git checkout player_state_notifications

export repos

git checkout-index -a -f --prefix=/destination/path/
git checkout-index -a -f --prefix=/Users/jrasmusson/Downloads/temp/

Note: double — dash on prefix

Multiple branches to find bug

git checkout -b aNewBranch1 SHA1 (test)
git checkout -b aNewBranch2 SHA2 (test)
git checkout -b aNewBranch3 SHA3 (got it!)

git branch -D aBranchToDelete
git difftool branch1 branch2

How to configure a new fork

git remote add upstream
git remote set-url --push upstream no_push
git config remote.pushdefault origin
git config --global push.default simple
git config --global pull.rebase true

How to checkout someone else remote branch

git remote add jr git@ghe.xxx.net:jr/project.git
git fetch jr branch
git checkout branch

How to checkout pull request gitlab

get PR number (i.e. #9)
fetch reference
git fetch origin pull/ID/head:BRANCHNAME
git checkout &amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;lt;em&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;gt;BRANCHNAME
You can now test it out

Link

How to cherry pick

git checkout
git log (note has of commit you want to cherry pick)
git checkout
git cherry-pick -x SHA

How to merge a remote branch

git merge remotes/origin/release/next

Misc commands

git log --author="xxx" --graph --oneline --no-merges
git log --pretty=oneline
git branch -a (shows all remote branches)
git log --grep="JRA-224:"
git rm --cached file.text (remove file from version control)

Add this to your bash file to do multiline git commit messages
export VISUAL="vim"
export EDITOR="vim"
git reflog // find any commit

~~xxx~~ cross out text in gitlab

Links

How to setup new iOS workflow


http://stackoverflow.com/questions/7244321/how-to-update-a-github-forked-repository

How to write a git commit message


https://github.com/rowanj/gitx

Tools

GitX

Leave a comment