Git 命令

2018-03-08 15:02:11 阅读:25 编辑

设置 remote

git remote set-url origin http://172.20.172.46:8888/git/crm.git

add filename # 添加到缓冲区
git add userapp/controllers/HomeController.php
commit -- 提交当前工作空间的修改内容
git commit -m 'modfiy home pages style'
pull -- 拉取 ( 只要是用于防止冲突)
git pull
push -- 用于将本地分支的更新,推送到远程主机

git push origin
# 从已经 git add 里删除文件
git reset HEAD file

创建分支

git branch -a // 列出本地及远程的分支
git branch store // 创建本地的分支 store
git checkout store // 切换至 store 分支
// 对文件的修改
git add .
git commit -m "xx"
git push origin store // 把 store 分支推到远程上

git pull origin wap // 拉取 wap 分支
合并分支
git checkout master
git merge store

git fetch origin // 当你的协作者再次从服务器上获取数据时,他们将得到一个新的远程分支 origin/store
删除分支
git branch -d store // 删除本地分支
git push origin :store // 删除远程分支

tag 标签

// 先提交所有文件
git tag -a v1.0 -m "基础的会员系统" // 创建一个 tag
git tag // 列表 tag
git tag -d v1.0 // 删除本地某个 tag
 git push origin :v1.0 // 删除远程某个 tag
git push origin v1.0 // 推至服务器

切换至某个 tag

git checkout v1.0 // 切换至 v1.0 的 tag

恢复某个文件

git checkout file

// 恢复到某个 commit (commit id 可以到 bitbucket.org 后台查找)

λ git reset --hard 0 c6 e7 a0
HEAD is now at 0 c6 e7 a0 add test route

Linux 免密码 pull,push

在~/ 下,touch 创建文件 .git-credentials, 用 VIM 编辑此文件,输入内容格式:

touch .git-credentials

VIM .git-credentials

https://edison2017:xxyy@bitbucket.org

  1. 在终端下执行 git config --global credential.helper store
  2. 可以看到~/.gitconfig 文件,会多了一项:
[credential]

helper = store

在当前项目目录下执行:

git remote set-url origin https://edison2017:xxyy@bitbucket.org/edison2017/91yunying.git

如果是撤销所有的已经 add 的文件:

git reset HEAD .
如果是撤销某个文件或文件夹:

git reset HEAD -filename

撤消上次的 commit

git reset HEAD~1