Git 常用命令

Git 常用命令

说明:在 codecademy 的 Git 教程中使用到的 Git 命令。

更多 Git 命令的详细介绍和使用方法可以参考 man 手册。

git workflow


git init

创建一个新的 Git 仓库

git status

检查 working directory 和 staging area 内容

git log

打印 commit 历史记录

git diff

显示 wroking directory 和 staging area 的不同

git add

将工作目录的文件提交到 staging area(git add 可用 git stage 替代)

git commit

将仓库中 staging area 的变更文件永久的储存起来

git add filename1 filename2 ...

提交多个文件到 staging area(git add 可用 git stage 替代)


###how to backtrack

git show HEAD

打印最近一次提交(HEAD commit)

git checkout HEAD filename

从 HEAD commit 中恢复 filename 指定的文件到工作目录

git reset HEAD filename

清空 staging area 并将 HEAD commit 中的文件恢复到 staging area

git reset commit_SHA

撤销指定 SHA 的提交及之后的提交历史


git branch


git branch

打印当前分支

git branch new_branch_name

新建名为 new_branch_name 的分支

git checkout branch_name

选择名为 branch_name 的分支

git merge branch_name

将名为 branch_name 的分支合并到当前分支

可以将 merge 操作理解为对 master 的快进

Git 合并新的 commits ,快进 master 更新到 branch_name

branch conflict

当将要合并的两个分支中的同一个 commit 文件同一行都被修改,合并时将发生冲突。

这种冲突需要我们来决定保留哪一个。

git branch -d branch_name

删除分支


### Git TeamWork

git clone remote_location clone_name

将 remote_location 指定的远程库克隆到 clone_name 指定的目录下

git remote -v

列出所有 Git 远程项目

git fetch

查看远程库的修改(不能 view 具体细节,也不能更改)

git merge origin/master

将远程库新的修改更新到本地分支

git push origin my_branch

将本地名为 my_branch 的分支推送到远程仓库

posted @ 2018-07-20 15:36  Skipper-  Views(214)  Comments(0Edit  收藏  举报