Git is a distributed version control system.
Linus created open-sourced Linux in 1991 and wrote Git using C in 2005.
Central VS Distributed:
Central version control:stores each developer's work in the central repository.
Distributed version control:takes a peer-to-peer approach to version control and gives each developer a local copy of the entire development history, and changes are copied from one such repository to another.
Differences:
1.No canonical, reference copy of the codebase exists by default; only working copies.
2.Common operations (such as commits, viewing history, and reverting changes) are fast, because there is no need to communicate with a central server.
3.Communication is only necessary when sharing changes among other peers.
4.Each working copy effectively functions as a remote backup of the codebase and of its change-history, protecting against data loss.
5.Numerous different development models are possible, such as development / release branches or a Commander / Lieutenant model, allowing for efficient delegation of topical developments in very large projects. Lieutenants are project members who have the power to dynamically decide which branches to merge.
6.Network is not involved for common operations.
7.Avoids relying on one physical machine as a single point of failure.
A Git project can be thought of as having three parts:
1.A Working Directory:where you will be doing all the work
2.A Staging Area:where you will list changes you make to the working directory
3.A Repository:stores changes as different versions of the project.
git init: creates a new Git repositoty
git status:inspects the contents of the working directory and staging area
git add: adds files from the working directory to the staging area
git diff: shows the differences between the working directory and the staging area
git commit: permanently stores file changes from the staging area in the repository
git log:shows a list of all previous commits. A 40-character code, called a SHA that identifies the commit.
HEAD is the most recent commit
git checkout HEAD filename: discards recent changes in the working directory
git reset HEAD filename: unstages recent changes in the staging area
git reset SHA: resets to a previous commit in commit history
git add filename_1 filename_2: adds miltiple files to the staging area
Branch:
git branch: lists all branches
git branch branch_name: creates a new branch
git checkout branch_name: switches from one branch to another
git merge branch_name: joins changes from one branch to another
git branch -d branch_name: deletes the branch
git clone: creates a local copy of a remote
git remote -v: lists a remote project
git fetch: fetches work from the remote into the local
git merge origin/master: merges origin/master into local
git push origin <branch_name>: pushes a local branch to origin remote
网友评论