五、Github的使用(1)(github,使用,用,开发技术)

时间:2024-05-07 03:08:41 作者 : 石家庄SEO 分类 : 开发技术
  • TAG :

29、公私钥的创建于配置github
为了在本地更好的操作远程仓库,可以在本地与远程仓库之间配置公私钥连接,首先可以查看本地是否有公私钥,如果没有可以使用以下命令生成。

$ ls ~/.ssh/ #查看是否存在公私钥id_rsa id_rsa.pub known_hostsssh-keygen -t rsa -b 4096 -C "your_email@example.com" #如果不存在可使用该命令生成

生成公私钥后,将公钥配置到github上。点击头像,进入Your Profile->SSH and GPG Keys即可进入配置公钥界面
五、Github的使用(1)
五、Github的使用(1)

30.在GitHub上创建个人仓库
点击Create a repository链接
五、Github的使用(1)
创建选项界面
五、Github的使用(1)
创建成功后界面
五、Github的使用(1)
31.把本地仓库同步到GitHub
首先将github的仓库地址配置到本地,可以在箭头指示的地方获取仓库的地址
五、Github的使用(1)

$ git remote -vzhineng file:///d/git_learning/.git (fetch)zhineng file:///d/git_learning/.git (push)$ git remote add github git@github.com:embedlinux/git_learning.git$ git remote -vgithub git@github.com:embedlinux/git_learning.git (fetch)github git@github.com:embedlinux/git_learning.git (push)zhineng file:///d/git_learning/.git (fetch)zhineng file:///d/git_learning/.git (push)

将本地文件推送到github上,此时可以知道Jone和temp分支push成功,而master失败

$ git push github --allCounting objects: 16, done.Delta compression using up to 4 threads.Compressing objects: 100% (9/9), done.Writing objects: 100% (16/16), 1.29 KiB | 77.00 KiB/s, done.Total 16 (delta 2), reused 0 (delta 0)To github.com:embedlinux/git_learning.git * [new branch] Jone -> Jone * [new branch] temp -> temp ! [rejected] master -> master (fetch first)error: failed to push some refs to 'git@github.com:embedlinux/git_learning.git'hint: Updates were rejected because the remote contains work that you dohint: not have locally. This is usually caused by another repository pushinghint: to the same ref. You may want to first integrate the remote changeshint: (e.g., 'git pull ...') before pushing again.hint: See the 'Note about fast-forwards' in 'git push --help' for details.

此时由于github上和本地的master分支发生冲突,因此需要merge

$ git fetch github master #获取远程master分支remote: Enumerating objects: 3, done.remote: Counting objects: 100% (3/3), done.remote: Compressing objects: 100% (2/2), done.remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0Unpacking objects: 100% (3/3), done.From github.com:embedlinux/git_learning * branch master -> FETCH_HEAD * [new branch] master -> github/master$ git checkout master #本地切换到master分支Switched to branch 'master'$ git branch -av Jone f0b5fe2 Add a file* master e0326fb Merge three commits temp b0fc955 Merge three commits remotes/github/Jone f0b5fe2 Add a file remotes/github/master 831e37e Initial commit remotes/github/temp b0fc955 Merge three commits remotes/zhineng/Jone f0b5fe2 Add a file$ git merge github/master fatal: refusing to merge unrelated histories$ git merge --allow-unrelated-histories github/master #合并远程分支Merge made by the 'recursive' strategy. LICENSE | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 LICENSE$ git push github master #再次push到github上,成功Counting objects: 2, done.Delta compression using up to 4 threads.Compressing objects: 100% (2/2), done.Writing objects: 100% (2/2), 373 bytes | 186.00 KiB/s, done.Total 2 (delta 0), reused 0 (delta 0)To github.com:embedlinux/git_learning.git 831e37e..707f0f8 master -> master

五、Github的使用(1)

32.不同人修改了不同文件如何处理
当不同的人工作在同一个branch,但是修改的是不同文件时,此时可以使用merge命令对文件进行更新。例如,当前在远程修改了Jone分支的read1.txt文件。
五、Github的使用(1)
在本地修改"second.txt"文件

$ git checkout JoneSwitched to branch 'Jone'Your branch is up to date with 'zhineng/Jone'.$ echo "Update the file " >> second.txt$ git add .$ git commit -m"Update second file"[Jone 568a695] Update second file 1 file changed, 1 insertion(+)$ git push github Jone #此时由于本地文件与远程不是同一个commit,出现问题To github.com:embedlinux/git_learning.git ! [rejected] Jone -> Jone (fetch first)error: failed to push some refs to 'git@github.com:embedlinux/git_learning.git'hint: Updates were rejected because the remote contains work that you dohint: not have locally. This is usually caused by another repository pushinghint: to the same ref. You may want to first integrate the remote changeshint: (e.g., 'git pull ...') before pushing again.hint: See the 'Note about fast-forwards' in 'git push --help' for details.$ git fetch github$ git branch -av* Jone 568a695 [behind 2] Update second file master 707f0f8 Merge remote-tracking branch 'github/master' temp b0fc955 Merge three commits remotes/github/Jone 139cca2 Update read1.txt remotes/github/master 707f0f8 Merge remote-tracking branch 'github/master' remotes/github/temp b0fc955 Merge three commits remotes/zhineng/Jone 0b88b5a Merge remote-tracking branch 'github/Jone' into Jone$ git merge remotes/github/Joneerror: Your local changes to the following files would be overwritten by merge: read1.txtPlease commit your changes or stash them before you merge.Aborting$ git merge remotes/github/JoneMerge made by the 'recursive' strategy.$ git push githubCounting objects: 6, done.Delta compression using up to 4 threads.Compressing objects: 100% (5/5), done.Writing objects: 100% (6/6), 624 bytes | 156.00 KiB/s, done.Total 6 (delta 3), reused 0 (delta 0)To github.com:embedlinux/git_learning.git 139cca2..00233dd Jone -> Jone

33.不同人修改了同文件的同区域如何处理
当在开发中,不同工作人员对同一个文件的相同区域做了修改时,此时git进行merge就会发生错误,需要手工进行merge,确定需要保留的内容。首先远程修改first1.md文件。
五、Github的使用(1)

$ echo "Update the file on local" >> first.md #本地也修改该文件$ git commit -am"Update first.md"[Jone b6870f1] Update first.md 1 file changed, 1 insertion(+)$ git fetch github #获取远程仓库remote: Enumerating objects: 5, done.remote: Counting objects: 100% (5/5), done.remote: Compressing objects: 100% (3/3), done.remote: Total 3 (delta 1), reused 0 (delta 0), pack-reused 0Unpacking objects: 100% (3/3), done.From github.com:embedlinux/git_learning 00233dd..c87da97 Jone -> github/Jone$ git branch -av* Jone b6870f1 [ahead 3, behind 1] Update first.md master 707f0f8 Merge remote-tracking branch 'github/master' temp b0fc955 Merge three commits remotes/github/Jone c87da97 Update first.md remotes/github/master 707f0f8 Merge remote-tracking branch 'github/master' remotes/github/temp b0fc955 Merge three commits remotes/zhineng/Jone 0b88b5a Merge remote-tracking branch 'github/Jone' into Jone$ git merge c87da97 #由于远程和本地修改相同文件,此时无法mergeAuto-merging first.mdCONFLICT (content): Merge conflict in first.mdAutomatic merge failed; fix conflicts and then commit the result.$ vim first.md #手工修改冲突文件

修改前
五、Github的使用(1)
修改后,同时保留远程和本地的修改
五、Github的使用(1)

$ git commit -am"Merge conflict file" #再次提交[Jone c2568ff] Merge conflict file$ git push github --all #push成功Counting objects: 6, done.Delta compression using up to 4 threads.Compressing objects: 100% (5/5), done.Writing objects: 100% (6/6), 601 bytes | 150.00 KiB/s, done.Total 6 (delta 2), reused 0 (delta 0)To github.com:embedlinux/git_learning.git c87da97..c2568ff Jone -> Jone
 </div> <div class="zixun-tj-product adv-bottom"></div> </div> </div> <div class="prve-next-news">
本文:五、Github的使用(1)的详细内容,希望对您有所帮助,信息来源于网络。
上一篇:HTML 之 常用标签下一篇:

8 人围观 / 0 条评论 ↓快速评论↓

(必须)

(必须,保密)

阿狸1 阿狸2 阿狸3 阿狸4 阿狸5 阿狸6 阿狸7 阿狸8 阿狸9 阿狸10 阿狸11 阿狸12 阿狸13 阿狸14 阿狸15 阿狸16 阿狸17 阿狸18