git

Distributed vs Centralised Versioning

Git

  • Works on snapshots of what files look like in each commit.

Git has 3 States and the workflow of using git is centered around these 3:

  1. Modified - file changed (Working Directory)

  2. Staged - Modified file is marked (in Staging area)

  3. Committed - (to .git directory, which is the repo)

.git stores metadata and object database for the project.

Initialise a repo

git init

-> creates .git sub-folder -> Remove the .git file, and all git related info for the project/repo is removed

Clone repo

git clone

See status of files

git status

-> Files are in two states, tracked (in the last commit) or untracked (current file) -> Used to see the conflict

Stage all untracked files in the specified directory

git add

Commits staged files

git commit

-m => Specifies Commit Message. Usually need to include when committing -> Follow the conventions!

-a => Like an "all" option. Auto-includes all tracked files into commits, and skips the staging phase

Ignore files to track

  • Done in .gitignore file, where therer are simple regex applied to file types.

Unmodify modified file:

git checkout

Remove file from Git tracking

git rm --cached 
git commit

-> Removes file from remote git, but locally exists.

Undo last commit

git revert HEAD
git commit

Check logs???

git log --oneline
git log --stat

Create a new branch

git branch

Switch to another branch

git checkout -b

-> the HEAD then points to the branch specified

Merging Branches

git checkout -b 
git merge

Push to Remote

git push

Pull to Remote

git pull

Directed Acyclic Graph ??? (more info- search online)

  • Each commit is a graph node, with a unique ID using SHA 1 hash

  • Each node points to the parent commit, except the first commit

  • Commits may have the same parent

  • HEAD: points to the current branch

Branching

  • Git is very good for frequent branching and merging.

  • A branch is just a pointer to one commit

  • Lightweight and cheap to create and destroy

Three Way Merge(??) Slide 23 and Slide 24 confusion

Last updated