Git 常用命令 笔记

初始化版本仓库

新建一个版本仓库

git init

克隆远程版本库

git clone [你的git地址] [文件夹名]

例:
git clone http://github.com/CosmosHua/locate new
git clone http://github.com/CosmosHua/locate.git new
git clone git://github.com/CosmosHua/locate new
git clone git://github.com/CosmosHua/locate.git new

配置

配置用户名

git config --global user.name '用户名'

配置邮箱地址

git config --global user.email [邮箱]

提交

添加文件到暂存区

git add [文件名] [文件名]

例:添加所有文件到暂存区 git add .

将暂存区内容添加到仓库

git commit -m '改动备注'

从暂存区移除

git rm [文件名]

本地分支提交远程分支

git push origin [本地分支名]

获取最新远程仓库代码

git pull

修改

重名名文件

git mv [旧文件] [新文件]

查看

查看本地分支

git branch

查看远程仓库

git remote -v

查看暂存区文件

git status -s

是否有修改

git status

查看提交历史记录

git log

分支管理

创建一个分支

git branch [分支名]

切换分支

git checkout [目标分支]

例: git checkout origin/master

创建并切换到新分支

git checkout -b [分支名]

合并分支(目标分支合并到当前分支)

git merge [目标分支]

删除分支

git branch -d [目标分支]

放弃本地修改 强制更新

git fetch --all
git reset --hard origin/master

[参考]

https://git-scm.com/book/zh/v1/Git-基础-远程仓库的使用

http://www.runoob.com/git/git-basic-operations.html

http://blog.csdn.net/miueugene/article/details/45306589

http://blog.csdn.net/leedaning/article/details/51304690







不断更新整理中。。。。



以下待整理

git checkout . #本地所有修改的。没有的提交的,都返回到原来的状态
git stash #把所有没有提交的修改暂存到stash里面。可用git stash pop回复。
git reset --hard HASH #返回到某个节点,不保留修改。
git reset --soft HASH #返回到某个节点。保留修改

git clean -df #返回到某个节点
git clean 参数
-n 显示 将要 删除的 文件 和 目录
-f 删除 文件
-df 删除 文件 和 目录

也可以使用:

git checkout . && git clean -xdf

http://www.yiibai.com/git/git_fetch.html

猜你喜欢

转载自www.cnblogs.com/BooneX/p/9238358.html
今日推荐