Git 简介
2018, Jan 17
BASIC GIT WORKFLOW
- Git is the industry-standard version control system for web developers
- Use Git commands to help keep track of changes made to a project:
git init
creates a new Git repositorygit status
inspects the contents of the working directory and staging areagit add
adds files from the working directory to the staging areagit diff
shows the difference between the working directory and the staging areagit commit
permanently stores file changes from the staging area in the repositorygit log
shows a list of all previous commits
HOW TO BACKTRACK
git checkout HEAD filename
: Discards changes in the working directory.git reset HEAD filename
: Unstages file changes in the staging area.git reset commit_SHA
: Resets to a previous commit in your commit history.
Additionally, you learned a way to add multiple files to the staging area with a single command:
git add filename_1 filename_2
GIT BRANCHING
git branch
: Lists all a Git project’s branches.git branch branch_name
: Creates a new branch.git checkout branch_name
: Used to switch from one branch to another.git merge branch_name
: Used to join file changes from one branch to another.git branch -d branch_name
: Deletes the branch specified.
GIT TEAMWORK
git clone
: Creates a local copy of a remote.git remote -v
: Lists a Git project’s remotes.git fetch
: Fetches work from the remote into the local copy.git merge origin/master
: Mergesorigin/master
into your local branch.git push origin
: Pushes a local branch to theorigin
remote.
Git projects are usually managed on Github, a website that hosts Git projects for millions of users. With Github you can access your projects from anywhere in the world by using the basic workflow you learned here.