codecademy 上的Git教程
-
git init
:初始化一个Git 仓库 -
Git项目由三部分组成
- Working Directory:你做所有事情所在的工作区
- Staging Area:where you'll list changes you make to the working directory,列出你对工作区做出的改变
- A Repository: where Git permanently stores those changes as different versions of the project,储存项目的不同版本
-
git status
: 查看工作区的变化 -
git add filename
: 添加文件到 staging area; -
git diff filename
: 查看工作区某文件 与 staging area 对应文件的差别; -
git commit
:提交staging area 中的文件到库中永久保存; -
git log
:打印出提交历史 -
git show HEAD
:Git 中 当前所在的commit 称为HEAD
使用本命令可以查看当前所在HEAD; -
git checkout HEAD filename
:恢复所修改文件为最后一次add后的状态; -
git add filename_1 filename_2
可同时提交多个文件到stageing area
; -
git reset HEAD filename
当某个文件已经提交到了staging area
,想要把它从staging area
中删除可执行此命令; -
git reset SHA
:取commit的SHA 前7位即可; 如git reset 1234567
,版本回滚到对应commit; -
git branch
:查看所有分支;*
所在的分支为当前分支; -
git branch new_branch
:创建新分支new_branch
,注意这个名字应该和你的用途想匹配; -
git checkout branch_name
:切换到分支branch_name
; -
git merge branch_name
:合并分支branch_name
到当前分支;如果有冲突,会提示冲突,需要手动修改后,再次提交; -
git branch -d branch_name
:删除某分支; -
git clone remote_location clone_name
:克隆远程分支,远程分支地址remote_location
,克隆到本地之后的命名clone_name
; -
git remote -v
可以查看当前Git 项目的 多个 远程地址; -
git fetch
:This command will not merge changes from the remote into your local repository. It brings those changes onto what's called a remote branch..查看,本地分支与远程分支比起来有哪些不同; -
git merge origin/master
:合并本地master分支和远程master分支; -
git 工作流:
- Fetch and merge changes from the remote
- Create a branch to work on a new project feature
- Develop the feature on your branch and commit your work
- Fetch and merge from the remote again (in case new commits were made while you were working)
- Push your branch up to the remote for review
-
git push origin your_branch_name
:推送分支到源