- 获取 Git 仓库
通常有两种获取 Git 项目仓库的方式:
- 将尚未进行版本控制的本地目录转换为 Git 仓库;
- 从其它服务器 克隆 一个已存在的 Git 仓库。
两种方式都会在你的本地机器上得到一个工作就绪的 Git 仓库。
推送现有文件夹
首先需要进入该项目目录中
cd /c/user/my_project
之后执行:
git init git remote add origin git@git-server:zhangcx/a.git git add . git commit -m "Initial commit" git push -u origin master
检查当前文件状态
git status
忽略文件
cat .gitignore
查看历史提交
git log //查看历史提交由近到远依次显示 git log -p -2 //查看历史提交并可查看提交的差异 git log --stat
撤销操作
git commit --amend
查看远程仓库
git remote -v
添加远程仓库
git remote origin git remote add pb https://github.com/paulboone/ticgit git remote -v origin https://github.com/schacon/ticgit (fetch) origin https://github.com/schacon/ticgit (push) pb https://github.com/paulboone/ticgit (fetch) pb https://github.com/paulboone/ticgit (push)
从远程仓库中抓取与拉取
git fetch
推送到远程仓库
git push origin master
查看某个远程仓库
git remote show origin
远程仓库的重命名与移除
git remote rename pb paul git remote remove paul
打标签
git tag -a v1.4 -m "my version 1.4" //创建标签并附注标签 git tag // 列出标签 git show v1.4 //查看标签信息
分支创建
git branch testing
分支切换
git checkout testing
新建一个分支并同时切换到那个分支上
这个命令相当于以上的分支创建和分支切换两条命令
git checkout -b iss53
分支的合并
你只需要检出到你想合并入的分支,然后运行 git merge 命令:
git checkout master git merge iss53
分支管理
git branch //查看分支 git branch --merged //查看哪些分支已经合并到当前分支 git branch --no-merged //查看所有包含未合并工作的分支



