Version Control with Git

Jon Loeliger & Matthew McCullough

I

Introduction

II

Basic Git Concepts

5

File Management and the Index

git add

git status

git add

git ls-files --stage

git rm --cached <filename>

git rm <filename>

IV

Commits

Commit

is used to

record changes to a repository

ref

is

an SHA1 hash ID that refers to an object within the Git object store.

local topic branch names, remote tracking branch names, tag names ...

git symbolic-ref HEAD

master ,origin/master ,v1.0.0 ,HEAD ,ORIG_HEAD ,FETCH_HEAD ,MERGE_HEAD ,master~3^2^

V

Branches

Branch

is

the fundamental means of launching a separate line of development within a software project.

for

  • individual customer release
  • a development phase
  • a single feature or research
  • the work of an individual contributor

Branch

conflict

uncommitted changes when checking out new branch

solve

  • git commit; git checkout new-branch
  • git checkout -m new-branch

Branch

  • git checkout -b new-branch start-point
  • = git branch new-branch start-point + git checkout new-branch
  • detached HEAD
  • git merge dev (at master)
  • git branch -d [local branch]
  • git push origin --delete [remote branch]

V

Diffs

Diff

  • git diff
  • git diff commit
  • git diff --cached commit
  • git diff commit1 commit2
  • git diff master..dev
  • git diff --stat master~5 master Documentation/git-add.txt
  • git diff -S"searchTerm" master~50

V

Merges

Merge with conflicts

be solved by

  • git diff
  • git status
  • git ls-files -u
  • git diff --ours
  • git diff --theirs
  • git diff --base
  • git diff $(git merge-base HEAD MERGE_HEAD)
  • git log --merge --left-right -p [file]
  • git checkout --ours / --theirs [file]
  • git reset --hard HEAD / ORIG_HEAD
  • git checkout -m

Merge Strategies

git merge -s [strategy] [branch]

  • Already up-to-date
  • Fast-forward
  • Resolve
  • Recursive
  • Octopus
  • Ours
  • Subtree

V

Altering Commits

Altering Commits

  • git reset --soft commit
  • git reset --mixed commit
  • git reset --hard commit
  • git cherry-pick commit
  • git revert commit
  • git commit --amend
  • git rebase master dev

V

The Stash and the Reflog

Stash

"interrupted work flow" "pull into a dirty tree"

  • git stash save "message"
  • git stash pop = git stash apply + drop
  • git stash drop
  • git stash apply
  • git stash show
  • git stash lish
  • git stash --include-untracked
  • git stash --all

Reflog

  • git reflog show
  • git reflog branch

V

Remote Repositories

Remote Repository

  • git remote
  • git fetch
  • git pull
  • git push
  • git ls-remote
  • git clone
  • git remote add origin URL
  • git update
  • git branch -a
  • git push origin master
  • git ls-remote origin
  • git remote show origin
  • git pull = git fetch + git merge/rebase

Thank you

@tiven.wang