标签:git 远程协作
1.ssh-keygen -t rsa -C "**@**” //注: **@**你自己注册的邮箱
2. eval "$(ssh-agent -s)”
3. ssh-add ~/.ssh/id_rsa
4. vim ~/.ssh/id_rsa.pub
5.ssh -T git@github.com
三、git 远程协作的主要命令:
1.git clone 用来获取一个远程仓库
2.git fetch 用来获取远程仓库的所有分支以支数据
3.git pull 是 get fetch 和git merge的组合操作
4.git push 用来所本地的数据推送到远程仓库中去
git clone支技以下协议
ssh;//[user@]host.xz[:port]/path/to /repo.git/
git://host.xz[:port]/path/to/repo.git/
http[s]://host.xz[:port]/path/to/repo.git/
ftp[s]://host.xz[:port]/path/to/repo.git/
rsync://host.xz/path/to/repo.git/
ftp.rsync分别是数据更新与同步的协议,通常使用前面三个协议
四、在github上建一个仓库并git clone下来:
git clone https://github.com/baitxaps/playDrama.git
在github上修改一些文件并保存,并在本地进行如下操作:
hairongchen:~ (master #)$ cd playDrama/
hairongchen:playDrama (master)$ git fetch
remote: Counting objects: 3, done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), done.
From https://github.com/baitxaps/playDrama
9bbbaf3..429e70d master -> origin/master
hairongchen:playDrama (master)$ git log --oneline --decorate --graph --all
* 429e70d (origin/master, origin/HEAD) Create ffmpegPlayer.h
* 9bbbaf3 (HEAD, master) Update README.md
* 7f70d13 Initial commit
2.指针指向刚修改的文件
hairongchen:playDrama (master)$ git merge origin/master
Updating 9bbbaf3..429e70d
Fast-forward
ffmpegPlayer.h | 3 +++
1 file changed, 3 insertions(+)
create mode 100644 ffmpegPlayer.h
hairongchen:playDrama (master)$ git lol
429e70d Create ffmpegPlayer.h
9bbbaf3 Update README.md
7f70d13 Initial commit
3.添加到历史当中去
hairongchen:playDrama (master)$ vim ffmpegPlayer.h
hairongchen:playDrama (master *)$ git add ffmpegPlayer.h
hairongchen:playDrama (master +)$ git commit -m "modify ffmpegPlayer.h"
[master c9b3708] modify ffmpegPlayer.h
1 file changed, 1 insertion(+), 1 deletion(-)
3.解决冲突
上面3中已经用git 添加到历史当中去了
1?在github上修改ffmpegPlayer.h 并保存
2.用本地更新推送到服务器时,用git push时出现:
hairongchen:playDrama (master)$ git push
Username for ‘https://github.com‘: baitxaps
Password for ‘https://baitxaps@github.com‘:
To https://github.com/baitxaps/playDrama.git
! [rejected] master -> master (fetch first)
error: failed to push some refs to ‘https://github.com/baitxaps/playDrama.git‘
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., ‘git pull ...‘) before pushing again.
hint: See the ‘Note about fast-forwards‘ in ‘git push --help‘ for details.
hairongchen:playDrama (master)$ git pull
remote: Counting objects: 3, done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 3 (delta 1), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), done.
From https://github.com/baitxaps/playDrama
429e70d..4477d57 master -> origin/master
Auto-merging ffmpegPlayer.h
CONFLICT (content): Merge conflict in ffmpegPlayer.h
Automatic merge failed; fix conflicts and then commit the result.
用vim ffmpegPlayer.h修改冲突并保存.并再提交
hairongchen:playDrama (master *+|MERGING)$ git add ffmpegPlayer.h
hairongchen:playDrama (master +|MERGING)$ git commit -m"ffmpegPlayer.h"
[master 5c90d21] ffmpegPlayer.h
4.再推送到服务器
hairongchen:playDrama (master)$ git push
Counting objects: 6, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (6/6), done.
Writing objects: 100% (6/6), 646 bytes | 0 bytes/s, done.
Total 6 (delta 2), reused 0 (delta 0)
To https://github.com/baitxaps/playDrama.git
4477d57..5c90d21 master -> master
5.创建tag分享
hairongchen:playDrama (master)$ git tag -a vo -m"tag for vo"
hairongchen:playDrama (master)$ git push
Everything up-to-date
看出默认是不出tag推送到远程仓库中的,所以提示所有的内容都是最新的,要把这个推送到远程仓库中怎么做呢?
用git push —tags 就把tag推送到远程仓库中去了,如:
hairongchen:playDrama (master)$ git push --tags
Counting objects: 1, done.
Writing objects: 100% (1/1), 151 bytes | 0 bytes/s, done.
Total 1 (delta 0), reused 0 (delta 0)
To https://github.com/baitxaps/playDrama.git
* [new tag] vo -> vo
在github上就有一个vo的tag
我们在github 上创建一个fetcher分支,当前分支为master
在终端上用 git pull 获取更新数据,发现fetcher分支更新下来了
hairongchen:playDrama (master)$ git pull
From https://github.com/baitxaps/playDrama
* [new branch] fetcher -> origin/fetcher
获取单独分支,因为上面已经更新,没有合并merge操作,只执行了一个fetch操作,把fetcher 内容记录到FETCH_HEAD文件中去
如:
hairongchen:playDrama (master)$ git pull origin fetcher
From https://github.com/baitxaps/playDrama
* branch fetcher -> FETCH_HEAD
Already up-to-date.
而 fetch 同样可以做同样的操作,只不过在服务器有更新的时候要手动的进行一下merge如:
hairongchen:playDrama (master)$ git fetch origin fetcher
From https://github.com/baitxaps/playDrama
* branch fetcher -> FETCH_HEAD
跟上面提示是一样的
6.既然更新只更新指定的数据,那么push 也可以push 指定的数据
我们修改ffmpegPlayer.h内容,并保存
vim ffmpegPlayer.h
添加到历史记录中
hairongchen:playDrama (master)$ vim ffmpegPlayer.h
hairongchen:playDrama (master *)$ git add ffmpegPlayer.h
hairongchen:playDrama (master +)$ git commit -m"add some text"
[master 20a9928] add some text
1 file changed, 1 insertion(+)
这个时候我们切换到vo上面
hairongchen:playDrama (master)$ git checkout vo
Note: checking out ‘vo‘.
You are in ‘detached HEAD‘ state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.
If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:
git checkout -b new_branch_name
HEAD is now at 5c90d21… ffmpegPlayer.h
使用git push origin master 分支单独把master分支提交到服务器上:
hairongchen:playDrama ((vo))$ git push origin master
Counting objects: 3, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 343 bytes | 0 bytes/s, done.
Total 3 (delta 1), reused 0 (delta 0)
To https://github.com/baitxaps/playDrama.git
5c90d21..20a9928 master -> master
这个时候仅仅推送master分支的内容,再切换到fetcher分支上去,
hairongchen:playDrama ((vo))$ git checkout fetcher
Branch fetcher set up to track remote branch fetcher from origin.
Switched to a new branch ‘fetcher‘
我们的本地的fetcher分支与跟服务器的fetcher分支有一个对应的关系,我样想把本地的fetcher删除之后,再把服务器的fetcher删掉:
1.切换到master分支:
hairongchen:playDrama (fetcher)$ git checkout master
Switched to branch ‘master‘
Your branch is up-to-date with ‘origin/master’.
2.在本地删除fetcher分支
hairongchen:playDrama (master)$ git branch -d fetcher
Deleted branch fetcher (was 5c90d21).
但服务器的分支还在的,使用git push —delete origin fetcher :
hairongchen:playDrama (master)$ git push --delete origin fetcher
To https://github.com/baitxaps/playDrama.git
- [deleted] fetcher
删除分支还有一种方法:
git push origin : fetcher (ps:origin 与冒号之间有一个空格)
用空来替换fetcher分支
hairongchen:playDrama ((vo))$ git push origin :fetcher
To https://github.com/baitxaps/playDrama.git
- [deleted] fetcher
四、github pull request流程
1.github上fork项目
2. git remote :从fork项目上获取更新
3.pull Request
操作步骤:
1.在 github上找一个仓库并点击fork按钮
2.把自己的仓库克隆下来:
git clone https://github.com/baitxaps/playDrama.git
3.git remote add upstream https://github.com/baitxaps/ffmpeg.git 给 https://github.com/baitxaps/ffmpeg.git 仓库取一个名字为upstream
4. 可以使用git remote -v 看一下仓库信息
5.获取upstream最新代码:
git checkout master
git fetch upstream
6.更新下来合并到master分支
git merge upstream/master,那么我样的仓库跟upstream一样的了
7.git reomte rename upstream ffmpeg 把upstream 改名为ffmepg
可用 git remote 查看刚改名的内容
8.删除ffmepg仓库
git remote rm ffmpeg
版权声明:本文为博主原创文章,未经博主允许不得转载。
标签:git 远程协作
原文地址:http://blog.csdn.net/baitxaps/article/details/47684349