Git 基础实践

2018-07-24  本文已影响0人  landon30

Git基础实践

配置

仓库配置(远端仓库已通过gitlab创建)

> git init
Initialized empty Git repository in /git-sample/.git/
> git remote -v
> git remote add origin git@gitlab.playcrab-inc.com:achilles/newbie.git
> git remote -v
origin  git@gitlab.playcrab-inc.com:achilles/newbie.git (fetch)
origin  git@gitlab.playcrab-inc.com:achilles/newbie.git (push)

Git基础操作

基础工作模式

  1. 用git push origin branch-name推送自己的修改
  2. 推送失败,则因为远程分支比你的本地更新,需要先用git pull试图合并

There is no tracking information for the current branch
git branch --set-upstream-to=origin/branch-name
git branch -u origin/branch

本地分支与远程分支关联

git push -u origin dev 推送的时候用-u参数关联

  1. 如果合并有冲突,则解决冲突,并在本地提交
  2. 没有冲突或者解决掉冲突后,再用git push origin branch-name推送就能成功

分支

关于合并

<<<<<<< HEAD
......
=======
......
>>>>>>> iss53

git tag

git tag 查看当前tag

-n

git tag -a v20171201 -m "20171201 for version audit"
git show v20171201
git push origin v20171201

git checkout -b branch_name tag_name

detached HEAD 快照 无法修改

需要从tag创建一个分支

进阶技巧

git stash

合并禁用fast-forward

git log查看的时候会有一个'commit' Merge branch 'merge-test'
如果合并是Fast-forward策略 则查看git log的时候 没有单独的commit表示曾经合并过
执行合并时,如果设定了non fast-forward选项,即使在能够fast-forward合并的情况下也会生成新的提交并合并
merge后master均会有分支修改的commit记录(无论是否删除分支)

经验:分支合并的时候禁用fast-fowrd
git merge --no-ff -m "merge" merge-test

git cherry-pick

git rebase

远程分支覆盖本地

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

其他

Eclipse#egit

Git Gonfiguration
Git Staging
Team

git reflog

显示整个仓库的commit包括已经撤销的commit

分支模型

image

参考

上一篇下一篇

猜你喜欢

热点阅读