![](https://i-blog.csdnimg.cn/blog_migrate/cce4cf2a6e1aaa49345b6a8701482d63.png)
利用Git进行协同开发:
例如项目主线master起始就有两个文件:1.txt / 2.txt 。分三个team进行开发不同功能。
branch1首先开发好了4.txt。branch3比较懒,啥也没干。branch2第二个开发好了最后一个功能3.txt。于是branch2需要在branch1的基础上进行rebase,merge。最后release。版本稳定后,再merge到master上。
master一般只接受最稳定的版本~
从Concepts学习git:https://jwiegley.github.io/git-from-the-bottom-up/
Git / GitLab / Github
三人协作开发:不一定需要用Github的服务器作为平台。可以在自己的服务器上部署一个GitLab。
cd ~
mkdir .ssh
cd ~/.ssh
ssh-keygen -t rsa -C "853802088@qq.com"
cat id_rsa.pub
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_rsa
ssh -T git@github.com
vim config
Host github.com
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa
cd ~
cd Desktop
mkdir gittest
cd gittest
git clone git@github.com:DrKLO/Telegram.git
git log
gitk
git branch -r:查看远端分支
git branch -a:查看所有分支
git config --list
$ git remote -v
origin git@github.com:DrKLO/Telegram.git (fetch)
origin git@github.com:DrKLO/Telegram.git (push)
(view)
git add 相当于提交到cache
git rm = rm 文件 + git add 文件
git pull 破坏性(远端拉下来,等于fetch+merge本地) / git fetch 指定分支 / git clone 全量
不同team要rebase的时候一般使用git fetch。
85380@DESKTOP-3S1KOHB MINGW64 ~/Desktop/gittest/Telegram (localdev)
$ git fetch origin dev
From github.com:DrKLO/Telegram
* branch dev -> FETCH_HEAD
git rebase FETCH_HEAD
git commit --amend:对上一次commit作修正
git commit --amend --author="JACK <alpha@qq.com>"
git commit --amend --reset-author:重置commit文件中的author
查看两个分支的不同:
85380@DESKTOP-3S1KOHB MINGW64 ~/Desktop/gittest/Telegram (test456)
$ git diff ^test123
diff --git a/2.txt b/2.txt
new file mode 100644
index 00000000..e69de29b
85380@DESKTOP-3S1KOHB MINGW64 ~/Desktop/gittest/Telegram (test456)
$ git checkout test123
Switched to branch 'test123'
85380@DESKTOP-3S1KOHB MINGW64 ~/Desktop/gittest/Telegram (test123)
$ git merge test456 --no-ff
Merge made by the 'recursive' strategy.
2.txt | 0
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 2.txt
学习源代码:
85380@DESKTOP-3S1KOHB MINGW64 ~/Desktop/gittest
$ git clone git@github.com:DrKLO/Telegram.git
Cloning into 'Telegram'...
remote: Enumerating objects: 2, done.
remote: Counting objects: 100% (2/2), done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 31984 (delta 0), reused 0 (delta 0), pack-reused 31982
Receiving objects: 100% (31984/31984), 174.27 MiB | 2.16 MiB/s, done.
Resolving deltas: 100% (16309/16309), done.
Updating files: 100% (5913/5913), done.
85380@DESKTOP-3S1KOHB MINGW64 ~/Desktop/gittest/Telegram (master)
$ git branch -r
origin/HEAD -> origin/master
origin/dev
origin/master
85380@DESKTOP-3S1KOHB MINGW64 ~/Desktop/gittest/Telegram (master)
$ git branch -a
* master
remotes/origin/HEAD -> origin/master
remotes/origin/dev
remotes/origin/master
85380@DESKTOP-3S1KOHB MINGW64 ~/Desktop/gittest/Telegram (master)
$ git remote -v
origin git@github.com:DrKLO/Telegram.git (fetch)
origin git@github.com:DrKLO/Telegram.git (push)
85380@DESKTOP-3S1KOHB MINGW64 ~/Desktop/gittest/Telegram (master)
$ git config --list
core.symlinks=false
core.autocrlf=true
core.fscache=true
color.diff=auto
color.status=auto
color.branch=auto
color.interactive=true
help.format=html
rebase.autosquash=true
http.sslcainfo=C:/Software/Git/mingw64/ssl/certs/ca-bundle.crt
http.sslbackend=openssl
diff.astextplain.textconv=astextplain
filter.lfs.clean=