git和github学习笔记

环境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.com
The 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)? yes
Warning: 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 0
Hi 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.tan
l@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 testlocalbash

l@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.git
fatal: Not a git repository (or any of the parent directories): .git

l@idea-PC MINGW64 /e/git/github/testlocalbash
$ git init
Initialized 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.git

l@idea-PC MINGW64 /e/git/github/testlocalbash (master)
$ git pull
Enter 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 0
Unpacking objects: 100% (3/3), done.
From github.com:tantaijin/testlocalbash
 * [new branch]      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


l@idea-PC MINGW64 /e/git/github/testlocalbash (master)
$ ls -l
total 0

l@idea-PC MINGW64 /e/git/github/testlocalbash (master)
$ git pull  git@github.com:tantaijin/testlocalbash.git
Enter passphrase for key '/c/Users/l/.ssh/id_rsa':
From github.com:tantaijin/testlocalbash
 * branch            HEAD       -> FETCH_HEAD

l@idea-PC MINGW64 /e/git/github/testlocalbash (master)
$ ls -l
total 1
-rw-r--r-- 1 l 197610 42 5月  30 11:10 README.md

l@idea-PC MINGW64 /e/git/github/testlocalbash (master)
$ echo README.md
README.md

l@idea-PC MINGW64 /e/git/github/testlocalbash (master)
$ cat README.md
# testlocalbash
only for test localbash

l@idea-PC MINGW64 /e/git/github/testlocalbash (master)
$ vi README.md

l@idea-PC MINGW64 /e/git/github/testlocalbash (master)
$ cat README.md
# testlocalbash
only for test localbash

2017-5-30 test


l@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.git
Enter 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 -> master

l@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 diffmerge
git config --global difftool.diffmerge.cmd '"C:\\Program Files\\SourceGear\\Common\\DiffMerge\\sgdm.exe" "$LOCAL" "$REMOTE"'
git config --global merge.tool diffmerge
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"'
git config --global mergetool.diffmerge.trustExitCode true

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

l@idea-PC MINGW64 /e/git/github/testlocalbash (master)
$ git config --global diff.tool diffmerge
git config --global merge.tool diffmerge
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"'
git config --global mergetool.diffmerge.trustExitCode true
l@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 diffmerge

l@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 true

l@idea-PC MINGW64 /e/git/github/testlocalbash (master)
$ git difftool

Viewing (1/1): 'README.md'
Launch 'diffmerge' [Y/n]? y


  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值