Git

From neil.tappsville.com
Revision as of 00:56, 4 November 2019 by Gonzo (talk | contribs)
Jump to navigationJump to search

Everyday

Stage and Add are the same.

git add <filename>  
 git status
 On branch mediatorLogging
 Your branch is up to date with 'origin/mediatorLogging'.

nothing to commit, working tree clean
git diff --staged   <-- see what changes we have made locally (pre-commit)
git commit 
git diff HEAD <-- see what changes we have committed (but not pushed)
git push

Local change history

git reflog

Repository change history

git log

Local Changes vs Repo

git log origin/master..HEAD

You can also view the diff using the same syntax

git diff origin/master..HEAD

Diff between the current branch and develop (origin of this branch hopefully) aka diff source and then current branch

git diff develop..feature/[branch_name]

If working in master (no branches used)

git diff origin/master...HEAD

Wipe all local changes and get the latest from the repo

git reset --hard        or       git checkout -- <file name>
git rebase origin/master

Or to store changes and re-apply them after pulling

git stash
git pull
git stash pop

Merge

Ensure the following are selected:

  • Delete source branch when merge request is accepted
  • Squash commits when merge request is accepted


https://stackoverflow.com/questions/4470523/create-a-branch-in-git-from-another-branch

$ git checkout -b myFeature dev

Creates MyFeature branch off dev. Do your work and then

$ git commit -am "Your message"

Now merge your changes to dev without a fast-forward

$ git checkout dev
$ git merge --no-ff myFeature

Now push changes to the server

$ git push origin dev
$ git push origin myFeature

Merge another branch upto a particular commit

git merge <id of commit>

Cherry pick a single commit and merge it

git cherry-pick <id of commit>

Forking to pull workflow

https://gist.github.com/Chaser324/ce0505fbed06b947d962

Updating a forked repo

https://help.github.com/en/articles/syncing-a-fork

git remote add upstream https://github.com/wanduow/openli.git

$ git fetch upstream
remote: Enumerating objects: 62, done.
remote: Counting objects: 100% (62/62), done.
remote: Compressing objects: 100% (8/8), done.
remote: Total 85 (delta 56), reused 60 (delta 54), pack-reused 23
Unpacking objects: 100% (85/85), done.
From https://github.com/wanduow/openli
 * [new branch]      develop    -> upstream/develop
 * [new branch]      master     -> upstream/master

git checkout master     <---- go into master -- we will merge something into here.
git diff HEAD..upstream/master <--- see what we are missing
git merge upstream/master   <---- merge this into the branch we have checked out

Disaster has struck

Rollback the last change (merge, commit) locally

git reset --hard HEAD~1