git和github学习笔记

来源:互联网 发布:python 打开html文件 编辑:程序博客网 时间:2024/06/07 10:25
环境windows8.1

一. 安装git

http://Git-scm.com/download/,

下载,然后一路默认安装.

二. 生成RSA公私钥

1. 打开bash,管理员权限运行,默认桌面上有快捷方式
2. 在bash里面输入ssh-keygen -t rsa -C "mail@email.com",后面是你邮箱地址,如果报错 too many arguments,命令没错的话就是没有已管理员权限运行bash,另外ssh-keygen之间没有空格。
3. 按提示操作,接下来是提示输入私钥和公钥文件名,这里我没改,也就是默认名称,
4. 生成后提示以下信息
Generating public/private rsa key pair.Enter file in which to save the key (/c/Users/l/.ssh/id_rsa):Created directory '/c/Users/l/.ssh'.Enter passphrase (empty for no passphrase):Enter same passphrase again:Your identification has been saved in /c/Users/l/.ssh/id_rsa.Your public key has been saved in /c/Users/l/.ssh/id_rsa.pub.


我电脑对应的目录是 C:\Users\l\.ssh ,下面有两个文件 id_rsa 和 id_rsa.pub,前者是私钥后者是公钥文件。

三. 关联github

1. 注册github账号,https://github.com,这里就不介绍了/
2. 点击人物头像的箭头,然后在左边选择ssh and gpgkeys,然后选择右边的new ssh keys.
3. title 随便输,key里面输入id_rsa.pub里面的全部内容,用记事本打开就可以看到。
4. 输入完提交后会提示输入密码,注意这个密码是你的github密码,不是私钥对应的密码(即不是bash里输入的密码)。
5. 验证是否添加成功
$ ssh git@github.comThe authenticity of host 'github.com (192.30.255.112)' can't be established.RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.Are you sure you want to continue connecting (yes/no)? yesWarning: Permanently added 'github.com,192.30.255.112' (RSA) to the list of known hosts.Enter passphrase for key '/c/Users/l/.ssh/id_rsa':PTY allocation request failed on channel 0Hi tantaijin! You've successfully authenticated, but GitHub does not provide shell access.Connection to github.com closed.


以上为验证是否添加成功信息,这样就表示成功了。
6. 配置用户名和邮箱
l@idea-PC MINGW64 ~$ git config --global user.name taijin.tanl@idea-PC MINGW64 ~$ git config --global user.email "yourmail@qq.com"


四. 创建仓库

1. 进入github网站,点击左上角那个猫类似的github log。

2. 在出来的界面上右下角,不是很靠下位置有关new repository按钮。

3. 在弹出来的界面上Repository name输入仓库名称,我这里取名testlocalbashDescription就随便写吧。 Initialize this repository with a README勾上,这个是为了把readme.md当作是否成功操作的标志文件。其它默认就行。

五. 实践

1. 随便找个用来测试的空目录,不解释了。以下是命令,熟悉git命令的可以无视.

l@idea-PC MINGW64 /e/git/github$ mkdir testlocalbashl@idea-PC MINGW64 /e/git/github$ cd testlocalbash/l@idea-PC MINGW64 /e/git/github/testlocalbash$ git remote add origin git@github.com:tantaijin/testlocalbash.gitfatal: Not a git repository (or any of the parent directories): .gitl@idea-PC MINGW64 /e/git/github/testlocalbash$ git initInitialized empty Git repository in E:/git/github/testlocalbash/.git/l@idea-PC MINGW64 /e/git/github/testlocalbash (master)$ git remote add origin git@github.com:tantaijin/testlocalbash.gitl@idea-PC MINGW64 /e/git/github/testlocalbash (master)$ git pullEnter passphrase for key '/c/Users/l/.ssh/id_rsa':remote: Counting objects: 3, done.remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0Unpacking objects: 100% (3/3), done.From github.com:tantaijin/testlocalbash * [new branch]      master     -> origin/masterThere 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> masterl@idea-PC MINGW64 /e/git/github/testlocalbash (master)$ ls -ltotal 0l@idea-PC MINGW64 /e/git/github/testlocalbash (master)$ git pull  git@github.com:tantaijin/testlocalbash.gitEnter passphrase for key '/c/Users/l/.ssh/id_rsa':From github.com:tantaijin/testlocalbash * branch            HEAD       -> FETCH_HEADl@idea-PC MINGW64 /e/git/github/testlocalbash (master)$ ls -ltotal 1-rw-r--r-- 1 l 197610 42 5月  30 11:10 README.mdl@idea-PC MINGW64 /e/git/github/testlocalbash (master)$ echo README.mdREADME.mdl@idea-PC MINGW64 /e/git/github/testlocalbash (master)$ cat README.md# testlocalbashonly for test localbashl@idea-PC MINGW64 /e/git/github/testlocalbash (master)$ vi README.mdl@idea-PC MINGW64 /e/git/github/testlocalbash (master)$ cat README.md# testlocalbashonly for test localbash2017-5-30 testl@idea-PC MINGW64 /e/git/github/testlocalbash (master)$ git commit -a[master 692bf84] message from local bash 1 file changed, 3 insertions(+)l@idea-PC MINGW64 /e/git/github/testlocalbash (master)$ git push  git@github.com:tantaijin/testlocalbash.gitEnter passphrase for key '/c/Users/l/.ssh/id_rsa':Counting objects: 3, done.Delta compression using up to 4 threads.Compressing objects: 100% (2/2), done.Writing objects: 100% (3/3), 290 bytes | 0 bytes/s, done.Total 3 (delta 0), reused 0 (delta 0)To github.com:tantaijin/testlocalbash.git   2428e7c..692bf84  master -> masterl@idea-PC MINGW64 /e/git/github/testlocalbash (master)$

2 .自己遇到的几个错误这里没有删除,可以直接看红色部分,那些是正确指令,另外,commit之前自己改变下文件readme.md内容。


六. 对比工具

对比工具的使用(当然你要是安装tortoisegit的话,也是可以的,界面化,还比较简单

1. 下载安装diffmerge免费的,http://www.sourcegear.com/diffmerge/downloads.php。

2.  打开git bash,输入以下命令。

git config --global diff.tool diffmergegit config --global difftool.diffmerge.cmd '"C:\\Program Files\\SourceGear\\Common\\DiffMerge\\sgdm.exe" "$LOCAL" "$REMOTE"'git config --global merge.tool diffmergegit config --global mergetool.diffmerge.cmd '"C:\\Program Files\\SourceGear\\Common\\DiffMerge\\sgdm.exe" --merge --result="$MERGED" "$LOCAL" "$(if test -f "$BASE"; then echo "$BASE"; else echo "$LOCAL"; fi)" "$REMOTE"'git config --global mergetool.diffmerge.trustExitCode true

3. 我电脑上的日志如下,其中 git difftool为使用方法

l@idea-PC MINGW64 /e/git/github/testlocalbash (master)$ git config --global diff.tool diffmergegit config --global merge.tool diffmergegit config --global mergetool.diffmerge.cmd '"C:\\Program Files\\SourceGear\\Common\\DiffMerge\\sgdm.exe" --merge --result="$MERGED" "$LOCAL" "$(if test -f "$BASE"; then echo "$BASE"; else echo "$LOCAL"; fi)" "$REMOTE"'git config --global mergetool.diffmerge.trustExitCode truel@idea-PC MINGW64 /e/git/github/testlocalbash (master)$ git config --global difftool.diffmerge.cmd '"C:\\Program Files\\SourceGear\\Common\\DiffMerge\\sgdm.exe" "$LOCAL" "$REMOTE"'l@idea-PC MINGW64 /e/git/github/testlocalbash (master)$ git config --global merge.tool diffmergel@idea-PC MINGW64 /e/git/github/testlocalbash (master)$ git config --global mergetool.diffmerge.cmd '"C:\\Program Files\\SourceGear\\Common\\DiffMerge\\sgdm.exe" --merge --result="$MERGED" "$LOCAL" "$(if test -f "$BASE"; then echo "$BASE"; else echo "$LOCAL"; fi)" "$REMOTE"'l@idea-PC MINGW64 /e/git/github/testlocalbash (master)$ git config --global mergetool.diffmerge.trustExitCode truel@idea-PC MINGW64 /e/git/github/testlocalbash (master)$ git difftoolViewing (1/1): 'README.md'Launch 'diffmerge' [Y/n]? y


原创粉丝点击