Android项目中Git的使用

2017-11-12  本文已影响0人  HH大雄

Android项目中Git的使用

git状态图

image.png

git项目

获取途径:自己新建项目和GitLab上已有的项目

一、自己新建的项目

  1. 初始化git仓库

git init

  1. 添加跟踪文件或添加修改文件

git add file1,file2...

  1. 提交到本地git仓库

git commit -m “comment”

  1. 提交到远程仓库。

本地Git仓库添加远程GitLab仓库
git remote add [shortname] [url]
推送项目到远程仓库:
git push -u [remote-name] [branchname]

二、克隆GitLab上已有项目

git clone url [project]

git rm fileName

git rm -f fileName

git rm --cached fileName

git reset HEAD fileName

git checkout -- fileName

分支管理

git branch [branch name]

git checkout [branch name]

git checkout –b [branch name]

git branch

git checkout master
git merge test

git branch –v

git branch –d [branch name]

git branch –D [branch name]

git branch --merge

git branch --no--merge

Git远程分支

远程跟踪分支是远程分支状态的引用。 它们是你不能移动的本地引用,当你做任何网络通信操作时,它们会自动移动。 远程跟踪分支像是你上次连接到远程仓库时,那些分支所处状态的书签。

git ls-remoe [remote name]

git remote show [remote name]

推送分支

推送新的本地分支到远程仓库

git push [remote name] [local branch name]
若想推送新的本地分支到远程仓库,但想修改远程仓库分支名:
git push [remote name][local branch name]:[remote branch name]

拉取服务器新的分支

如某个合作者上传了某个分支:git push origin test:test

git fetch origin

git merge origin/test

git checkout –b test origin/test

跟踪分支

从一个远程跟踪分支检出一个本地分支会自动创建一个叫做 “跟踪分支”(有时候也叫做 “上游分支”)。跟踪分支是与远程分支有直接关系的本地分支。 如果在一个跟踪分支上输入gitpull,Git能自动地识别去哪个服务器上抓取、合并到哪个分支。

git checkout –track [remote name]/[branch name]

  1. 设置已有的本地分支跟踪一个刚刚拉取下来的远程分支,或者想要修改正在跟踪的上游分支,你可以在任意时间使用-u或--set-upstream-to选项运行gitbranch来显式地设置。

git branch –u [remote name]/[branch name]

  1. 如果想要查看设置的所有跟踪分支,可以使用git branch的-vv选项

git branch –vv

拉取

删除远程分支

git push [remote name] --delete brandname

假设你已经通过远程分支做完所有的工作了 -也就是说你和你的协作者已经完成了一个特性并且将其合并到了远程仓库的master分支(或任何其他稳定代码分支)。可以运行带有--delete选项的git push命令来删除一个远程分支。

上一篇 下一篇

猜你喜欢

热点阅读