安卓深度探索(卷1)阅读笔记(第三章)

  这一章是关于git的使用入门,之前小了解却没有时间仔细去看,看完之后有学习到了新技能。

  

源码管理软件有gitsvncvs

sudo apt-get install git git-core#安装git

man git-checkout#查看帮助文档

git版本库分为本地和远程版本库

git init#创建空版本库会出现一个.git目录

echo “hello world” > helloworld.txt#创建helloworld.txt文件并添加一行hello world

#helloworld.txt文件添加到本地版本库的索引并且提交到版本库

git add helloworld.txt

git commit -m 'helloworld-master'

 

git log#显示日志

git checkout helloword.txt#恢复到上一次提交的文件

git branch -a#显示已有分支

git branch new-branch#创建新分支

git branch -D new-branch#删除本地刚建立的new-branch分支

git checkout new-branch#切换到new-branch分支

 




创建一个github账号并且创建一个开源项目

 

ssh-keygen -t rsa -C “邮箱账号#生成秘钥文件id_rsa公钥文件id_ras.pub

将生成的id_rsa.pub里面的内容全部粘贴到github账户的ssh管理中

ssh -T git@github.com#检测公钥和秘钥是否设置正确

 


设置上传者的信息

git config --global user.name “Your name”

git config --global user.email 1141802674@qq.com

 


git remote add origin git@github.com:2101648015pio/hello-world.git#设置hello world工程在github上的URI

git push -u origin master#上传本地库的文件

 


git clone git@hubgit.com: 2101648015pio/hello-world.git#下载整个工程

git pull origin master#获取某一分支


遇到的问题:

1.git push -u origin master

Warning: Permanently added the RSA host key for IP address '192.30.252.123' to the list of known hosts.

To git@github.com:2101648015pio/hello-world.git

! [rejected] master -> master (fetch first)

error: 无法推送一些引用到'git@github.com:2101648015pio/hello-world.git'

提示:更新被拒绝,因为远程版本库包含您本地尚不存在的提交。这通常是因为另外

提示:一个版本库已向该引用进行了推送。再次推送前,您可能需要先整合远程变更

提示:(如'git pull ...')。

提示:详见'git push --help' 中的'Note about fast-forwards' 小节。


解决:vim /etc/hosts#修改host

添加192.60.151.123 github.com

/etc/init.d/networking restart#重启网络


2.git push --force

warning: push.default 尚未设置,它的默认值在Git 2.0 已从'matching'

变更为'simple'。若要不再显示本信息并保持传统习惯,进行如下设置:


git config --global push.default matching


若要不再显示本信息并从现在开始采用新的使用习惯,设置:


git config --global push.default simple


push.default 设置为'matching' 后,git 将推送和远程同名的所有

本地分支。


Git 2.0 开始,Git 缺省采用更为保守的'simple' 模式,只推送当前

分支到远程关联的同名分支,即'git push' 推送当前分支。


参见'git help config' 并查找'push.default' 以获取更多信息。

'simple' 模式由Git 1.7.11 版本引入。如果您有时要使用老版本的Git

为保持兼容,请用'current' 代替'simple'


fatal: 当前分支hello 没有对应的上游分支。

为推送当前分支并建立与远程上游的跟踪,使用


git push --set-upstream origin hello


解决:git config --global push.default simple




3.git pull

warning: no common commits

remote: Counting objects: 6, done.

remote: Compressing objects: 100% (3/3), done.

remote: Total 6 (delta 0), reused 0 (delta 0), pack-reused 0

展开对象中: 100% (6/6), 完成.

来自github.com:2101648015pio/hello-world

* [新分支] master -> origin/master

There is no tracking information for the current branch.

Please specify which branch you want to merge with.

See git-pull(1) for details


git pull <remote> <branch>


If you wish to set tracking information for this branch you can do so with:


git branch --set-upstream-to=origin/<branch> master



解决:git push origin +master#强制更新



4.ssh-add

Enter passphrase for /home/jinliu/.ssh/id_rsa:

Identity added: /home/jinliu/.ssh/id_rsa (/home/jinliu/.ssh/id_rsa)



jinliu@wode:~$ ssh -T git@github.com


The authenticity of host 'github.com (192.30.252.120)' 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,192.30.252.120' (RSA) to the list of known hosts.

Hi 2101648015pio! You've successfully authenticated, but GitHub does not provide shell access.

--比你优秀的人尚在努力,这一点着实可怕。
原文地址:https://www.cnblogs.com/5pi0/p/5378263.html