以下内容来源于我的evernote笔记...
一:提交
1、设置git连接,创建ssh 密钥
2、在本地目录建立一个文件夹
mkdir ~/test
cd test
touch test.txt
3、初始化git
git init
git add . //将当前目录的所有内容,交由git管理。
git commit -m "new master"
git remote add origin git@github.com:coding/leetcode.git //设置远程连接
git remote -v //查看远程连接
git push -u origin master 将远程项目提交到远程仓库中。
二:下载
1、在别的主机上添加ssh密钥
2、git clone git@github.com:coding/test.git //download具体的项目。
三:删除
git rm test.txt
git commit -c "delete test.txt"
git push origin masterd
四:更新
git fetch origin//取得远程更新
git merge origin/master //将更新的内容合并到本地分支/master
五:down别人的项目
1、将别人的项目fork
2、建立本地目录并初始化
3、git remote add origin …
4、git pull origin master
大致就是这样的步骤。
六:杂碎
git remote rm origin //删除错误源
2015-03-04-001
echo "zh" > .gitignore
采用如上操作,排除zh目录到仓库之外。
2015-03-04-002
这里有一份git简易指南。
2015-03-04-003
git fetch 和 git pull
git fetch origin master
git log
-
p master
..
origin
/
master
git merge origin
/
master
相当于
git fetch origin master:tmp
git diff tmp
git merge tmp
git pull origin master
这条命令包括了fetch 和merge
2015-03-04-004
git fetch命令
git fetch <远程主机名> <分支名>
查看远程分支:
git branch -r
查看所有分支:
git branch -a
此会显示当前的分支(*)
2015-03-04-005
创建分支
git checkout -b feature_x
切换回主分支
git checkout master
2015-03-04-006
针对不同的项目,最好的方法是在本地创建单独的仓库,并在配置文件中配置好远程origin。
2015-03-04-007
git 配置
以下配置自动存放在 该文件中:~/.gitconfig
git config --global core.editor vim
git config --global merge.tool vimdiff
git config --global color.ui auto
git config --global user.name $name
git config --global user.email $email
2015-03-04-008
比较两个分支
git diff <source_branch> <target_branch>
2015-03-04-009
为什么
git fetch origin
与
git fetch origin master行为不一致。
git fetch origin master 实际上是将服务器的更新存放到master:FETCH_HEAD
而git fetch origin 则是将服务器的更新存放到origin/master。然后再git merge origin/master就可以到本地了。
2015-03-04-010
关于FETCH_HEAD的释义
stackoverflow的回答
FETCH_HEAD is a short-lived ref, to keep track of what has just been fetched from the remote repository. git pull first invokes git fetch, in normal cases fetching a branch from the remote; FETCH_HEAD points to the tip of this branch (it stores the SHA1 of the commit, just as branches do). git pull then invokes git merge, merging FETCH_HEAD into the current branch.
The result is exactly what you'd expect: the commit at the tip of the appropriate remote branch is merged into the commit at the tip of your current branch.
This is a bit like doing git fetch without arguments (or git remote update), updating all your remote branches, then running git merge origin/<branch>, but using FETCH_HEAD internally instead to refer to whatever single ref was fetched, instead of needing to name things.
2015-03-04-011
设置全局的.gitinore
git config --
global
core.excludesfile ~/.gitignore
建立一个范本。
git 分支
查看分支
git branch -a 查看所有分支
git branch -r 查看本地分支
创建分支
1、本地创建分支推到远程
git branch develop
git push -u origin develop
2、从远程获取一个分支
git checkout -b develop origin/develop
3、从本地获取一个分支
git checkout -b feature.1 develop
删除分支
git branch -d feature.1
切换分支
git checkout
合并分支
git pull origin develop 确保develop分支是最新的
git checkout develop
git merge feature.1
git push
git branch -d feature.1
合并发布分支 必须要同时合并到master和develop上
合并bug分支 必须要同时合并到master和develop上
打tag
一般有合并到master的请求,都需要打tag跟踪。
git tag -a 0.1 -m “tag explain"
git push —tags
分支命名
遵循git flow
主分支:master
开发分支: develop
功能分支:feature 采用feature-*命名 ,开发完成后,合并到develop上
git checkout develop
git merge -no-ff feature-x
预发布分支: release 采用release-* ,主要用于测试并修复一些问题。
比如release-1.2确认没有问题,合并到master分支
git checkout master
git merge —no-ff release-1.2
再合并到develop分支
git checkout develop
git merge —no-ff release-1.2
然后删除
git branch -d release-1.
修补bug分支: 从master分支上分出来的,采用fixbug-*命名。修复完成,合并到master 和 develop分支中。
2015-09- 28-000
关于upstream
一般只有同时存在多个远程仓库时才会用到--set-upstream。每个git branch可以有个对应的upstream。假设你有两个upstream,分别叫server1和server2,本地master branch的upstream是server1上的master,那么当你不带参数直接输入git pull或者git push时,默认是对server1进行pull/push。如果你成功运行"git push -u server2 master",那么除了本地branch会被push到server2之外,还会把server2设置成upstream。
2015-10-07-000
Command line instructions
Git global setup
git config --global user.name "cloudy"
git config --global user.email "test@test.com"
Create a new repository
git clone git@gitlab.com:cloudy/newa.git
cd newa
touch README.md
git add README.md
git commit -m "add README"
git push -u origin master
Existing folder or Git repository
cd existing_folder
git init
git remote add origin
git@gitlab.com:test/newa.git
git add .
git commit
git push -u origin master
2015-10-08-000
git 代码冲突解决办法
如果希望保留生产服务器上所做的改动,仅仅并入新配置项, 处理方法如下:
git stash
git pull
git stash pop
然后可以使用git diff -w +文件名 来确认代码自动合并的情况.
反过来,如果希望用代码库中的文件完全覆盖本地工作版本. 方法如下:
git reset --hard
git pull
其中git reset是针对版本,如果想针对文件回退本地修改,使用
git checkout HEAD file/to/restore
解决冲突,需要人工处理
2015-10-08-001
bug修改流程
git checkout fixbug-0.1
git add .
git commit -m “fixbug"
git push origin fixbug-0.1
git checkout master
git pull origin master
git merge fixbug-0.1
git push origin master
git checkout develop
git pull origin develop
git merge fixbug-0.1
git push origin develop
develop分支中拉取更新流程
git stash 暂存作业
git pull origin develop
git stash pop 合并作业
2015-10-09-000
git 解决冲突
首先敲一下git status
1、本地和服务器二选一
git checkout —ours xxx/A.java
git checkout —theirs xxx/A.java
2、丢弃本地修改,采用服务器上的
git reset —hard origin/master
git reset —hard ORIG_HEAD
3、不能丢弃本地修改,则对冲突文件进行手动合并,然后运行以下命令
git add filename
git commit -m “.."
4、废弃本次合并
git reset —hard HEAD
2015-10-10-000
拉取分支
git pull origin 分支名