Jeff
Jeff Cloud Systems Architect
1 min read

GIT Survival Guide

GIT Survival Guide

This is just a quick guide to get you out of GIT Hell. I tend to forget these commands so I wanted a place to document the GIT foo.

Create a Merge Request via CLI

git push \
  -o merge_request.create \
  -o merge_request.target=master \
  -o merge_request.title="MR 101" \
  -o merge_request.description="Added new test feature 101"

Note: if you are running GIT 2.10 - 2.17 use --push-option instead of -o

Reset back to a commit

### List things that have changed across branches
git reflog
git reset HEAD@{INDEX_ID}

Fix a Commit message

git commit --amend

Add a change to a current Commit

### Try to avoid this on public commits, only do on local commits
### Make your changes and add your file
git add {filename}
git commit --amend --no-edit

Move a commit to a new Branch

I do this all the time. I commit to master and not a branch

### Create a new branch
git branch NewBranch
### Remove the last commit from master
git reset HEAD~ --hard
### Switch to new branch where your commit now lives
git checkout NewBranch

Move a commit to an existing Branch

### checkout the proper branch
git checkout ProperBranch
### Grab last mast commit
git cherry-pick master
### Remove the last commit from master
git checkout master
git reset HEAD~ --hard

Undo a specific commit

git log
git reverse {hash}

Undo changes to a single fike

### Find the hash
git log
git checkout {hash} -- /path/to/file
git commit -m "rolled back file"

GIT Diff staged changes

git diff --staged