git 在工作中的一些常见用法

git branch 列出当前的全部分支
git checkout master 检出仓库并且切换到该分支
git merge develop 将develop分支合并到当前分支

标签

git tag # 列出当前的全部标签
git checkout v5.4 切换到v5.4标签

  • 创建轻量标签
    git tag v0.1.2-light

  • 创建附注标签
    git tag -a v0.1.2 -m “0.1.2版本”

  • 查看标签信息
    用git show命令可以查看标签的版本信息:
    git show v0.1.2

  • 删除标签
    误打或需要修改标签时,需要先将标签删除,再打新标签。
    git tag -d v0.1.2

  • 删除远程标签
    git push origin :v1.1
    或者
    git push origin --delete tag V1.1

  • 标签发布
    通常的git push不会将标签对象提交到git服务器,我们需要进行显式的操作:
    git push origin v0.1.2 # 将v0.1.2标签提交到git服务器
    git push origin --tags # 将本地所有标签一次性提交到git服务器

更新 .gitingnore 忽略文件的正确做法

  1. 首先使用 git rm -r --cached .idea/ 从本地缓存中移除已经被git缓存的目录或文件,-r` 用于遍历文件夹,如果只是单文件无需使用

  2. 然后更新 .gitignore 忽略掉目标文件

  3. 最后 git commit -m "We really don't want Git to track this anymore!"

在 git 中正确配置CRLF
http://blog.csdn.net/lysc_forever/article/details/42835203

git 中错误 add commit 的撤销
http://blog.csdn.net/kongbaidepao/article/details/52253774


如何通过git进行团队协作


以github的仓库为例,假定已经配置git并有了自己的github账号。

1,通过github,把团队代码仓库(Fork源)Fork一份到自己的github仓库;

2,从自己的github仓库clone代码到本地(开发用的电脑,Virtual machine..);
git clone git@github.com:Song2017/wordpress-azure.git(ssh key/http url)

3,新建一个分支,便于Fork源代码的管理
git checkout -b dev //新建并转到分支 dev

4,工作的代码应与团队保持一致,git remote update Fork源

git remote add upstream git@github.com:Source/joomla-azure.git //添加Fork源并设置别名upstream
git remote -v //查看本地仓库对应的远程仓库

//只会将本地库所关联的远程库的commit id更新至最新,代码不会更新,需要继续merge/rebase
git remote update upstream/git fetch upstream
git branch -a
git merge remotes/upstream/master
git pull upstream master //同步Fork源的代码至本地

5,Work with code in local repository.搬砖..

6, 提交到自己的github仓库
git status // 查看代码的状态
git add . // 添加所有操作过的代码文件
git commit -m "comment"//统一提交并注释
git push origin dev //向自己的github仓库推送代码 origin:clone的地址git@github.com:Song2017/wordpress-azure.git

7,通过github,向Fork源提出push request.团队管理人进行代码merge。

Tips
a, 推送冲突
$git push origin master
To github.com:Song2017/joomla-azure.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to ‘git@github.com:Song2017/joomla-azure.git’
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: ‘git pull …’) before pushing again.
hint: See the ‘Note about fast-forwards’ in ‘git push –help’ for details.
1,强制push
git push origin dev -f
2,创建分支
git branch [name]
git push origin [name]
3,查看修改过的code,修改掉冲突的代码

b,git 代码操作指令 远程地址 分支
git pull origin master
pull: 拉取远程仓库代码的指令
origin: 远程仓库的地址,默认为clone的仓库地址git@github.com:Song2017/wordpress-azure.git
master: 远程仓库的分支名称,默认为master

推送全部分支:
git push --all origin

推送全部tag:
git push origin --tags

远程tag 与 bransh命名不能冲突
https://blog.csdn.net/qq_32452623/article/details/76649109