周末终于把Git学了,目的是更好的理解和使用Github。附上操作命令的学习笔记~
Chap-1 Git workflow
Git commands - to help keep track of changes make to a project:
git init : create a new Git repository
git status: inspect the contents of the working directory and staging area
git add: adds files from the woking directory to the staging area
git diff: shows the difference between the working directory and the staging area
git commit: permanently store file changes form the staging area in the repository ( e.g.: git commit -m “add a line ” )
Chap-2 Backtrack in Git
git checkout HEAD filename: Discards changes in the working directory
git reset HEAD filename: Unstage file changes in the staging area
git reset commit_SHA: reset to a previous commit in your commit history
git add filename_1 filename_2 : add multiple files to the staging area with a single command
Chap-3 Branch (重点)
Git branching allows users to experiment with different versions of project by checking out separate branches to work on.
git branch: lists all a Git project’s branches. ( 1) include: master / other branches; 2) * mark means where you are)
-
git branch branch_name: creates a new branch
(The master and fencing branches are identical: they share the same exact commit history)
git checkout branch_name: used to switch from one branch to another ( commands on this branch have no impact on master)
git merge branch_name: used to join file changes from one branch to another (Fast-forward :The merge is a "fast forward" because Git recognizes that fencing contains the most recent commit. )
git branch -d branch_name: Deletes the branch specified
Chap-4 Git Teamwork
A remote is a Git repository that lives outside your Git project folder.
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: Merges origin/master into your local branch
git push origin branch_name: pushes a local branch to the origin remote
笔记来源于Codecademy网站。