git的学习笔记(一):git本地操做html
ssh-keygen -t rsa -C "your_email@example.com"
执行命令后会在用户的家目录生成.ssh的隐藏文件夹,文件夹里有公钥id_rsa.pub和私钥id_rsagit
在gitlab或者gitee网站添加密钥的方式与github添加密钥的方式相同github
git remote add github <remote URL> 使用https方式将本地仓库关联到远程仓库(远程仓库名默认为origin) git remote add github git@github.com:用户名/repo_name.git 使用git方式将本地仓库关联到远程仓库 git remote remove github 删除关联到本地的远程仓库,origin是远程库的名字 git branch --set-upstream-to=origin/smart smart 将分支smart设置为跟踪来自origin的远程分支smart git push 把本地的全部提交推送到默认的远程的仓库 git push github -all git pull github master 将远程origin代码拉到本地master分支 git push github master 将本地master分支代码推送到远端仓库 git clone <HTTP URLs/remote URL> 复制远程项目到本地
先切换到须要合并的分支,例如:本地master分支web
git checkout master
合并本地分支和远程分支shell
# 把本地分支和远程仓库的master这两个不相关,独立的分支合并 git merge --allow-unrelated-histories github/master
在弹出的窗口中修改内容并退出,即为commit的内容浏览器
不一样的人修改了同一个项目的不一样文件,且都已经提交到过程仓库时ssh
首先用户A把远程仓库的分支拉取到本地仓库ide
git fetch github git branch -av # 查看本地仓库和远程仓库的全部分支信息
在这个时间段内,另外一个用户B又在他的分支作修改并提交到远程仓库后,用户A使用 git push github 命令同步本地修改到远程仓库会提示异常gitlab
用户A的解决方法:学习
git fetch github # 拉取远程仓库的分支信息 git merge github/用户B的分支 # 把用户B的分支与本地分支进行合并 git push github # 推送到远程仓库
用户A修改某个文件,提交并同步到远程仓库
用户B也修改这个文件,而后commit,在同步到远程仓库时会报错
用户B解决方法:
git fetch git merge origin/用户A的远程分支 # 用户A修改后提交到哪一个分支,就合并哪一个分支 git push # 用户B同步分支到远程仓库的指定分支
用户A修改某个文件的某一行,提交并同步到远程仓库
用户B也修改这个文件的同一行,而后commit,在同步到远程仓库时会报错
用户B的解决方法:
git pull # 把远程仓库的用户A的修改拉取到本地并合并,会提示 conflict 修改冲突文件,解决冲突 git commit -m "commit message" # 提交修改 git push github # 同步到远程仓库
用户A修改文件名,提交并同步到远程仓库
用户B也修改这个文件的内容,而后commit,在同步到远程仓库时会报错
用户B的解决方法:
git pull # 把远程仓库的用户A的修改拉取到本地并合并,会提示修改合并后的提交信息 git push github # 同步到远程仓库
git会自动把用户B的文件名修改为用户A修改后的文件名
用户A修改文件名,提交并同步到远程仓库
用户B也修改这个文件的文件名,而后commit,在同步到远程仓库时会报错
用户B的解决方法:
git pull # 把远程仓库的用户A的修改拉取到本地并合并,并同时显示两个内容相同但文件名不一样的文件 git diff file1 file2 git status git rm file # 这里的file为没有被修改以前的文件名 git add file1 # 把 file1 添加到暂存区 git rm file2 # 删除 file1 git commit -m "commit message" git push
多人协做开发时,禁止使用的命令,会形成之前提交的信息丢失
git push -f # 强制 push
参考gitee网站:Git配置多个SSH-Key
ssh-keygen -t rsa -C 'xxxxx@qq.com' -f ~/.ssh/gitee_id_rsa ssh-keygen -t rsa -C 'xxxxx@qq.com' -f ~/.ssh/github_id_rsa ssh-keygen -t rsa -C 'xxxxx@qq.com' -f ~/.ssh/gitlab_id_rsa
# gitee Host gitee.com HostName gitee.com PreferredAuthentications publickey IdentityFile ~/.ssh/gitee_id_rsa # github Host github.com HostName github.com PreferredAuthentications publickey IdentityFile ~/.ssh/github_id_rsa # gitlab Host gitlab.com HostName gitlab.com PreferredAuthentications publickey IdentityFile ~/.ssh/gitlab_id_rsa
Administrator@DESKTOP-B5TMUVT MINGW64 ~/.ssh $ ssh -T git@gitee.com Warning: Permanently added the ECDSA host key for IP address '120.55.226.24' tothe list of known hosts. Hi SING890925! You've successfully authenticated, but GITEE.COM does not provide shell access. Administrator@DESKTOP-B5TMUVT MINGW64 ~/.ssh $ ssh -T git@github.com The authenticity of host 'github.com (13.229.188.59)' can't be established. RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added 'github.com,13.229.188.59' (RSA) to the list of known hosts. Hi renpingsheng! You've successfully authenticated, but GitHub does not provideshell access. Administrator@DESKTOP-B5TMUVT MINGW64 ~/.ssh $ ssh -T git@gitlab.com The authenticity of host 'gitlab.com (35.231.145.151)' can't be established. ECDSA key fingerprint is SHA256:HbW3g8zUjNSksFbqTiUWPWg2Bq1x8xdGUrliXFzSnUw. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added 'gitlab.com,35.231.145.151' (ECDSA) to the list of known hosts. Welcome to GitLab, @renpingsheng!
以下图所示
git help --web log # 打开浏览器查看git log帮助文档