# Learn_Git **Repository Path**: Stubborner/learn_git ## Basic Information - **Project Name**: Learn_Git - **Description**: Learn_git学习git的使用 - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2021-10-11 - **Last Updated**: 2022-06-14 ## Categories & Tags **Categories**: Uncategorized **Tags**: Git, GitHub ## README ### SSH的基本使用 远程连接 以用户名user,登陆远程主机host ```bash $ ssh user@host ``` ssh端口默认是22,使用p参数,可以修改这个端口 ```bash $ ssh -p 222 user@host ``` 口令登陆 如果是第一次登陆对方主机,系统就会出现如下提示: ```bash The authenticity of host 'host (12.18.429.21)' can't be established. RSA key fingerprint is 98:2e:d7:e0:de:9f:ac:67:28:c2:42:2d:37:16:58:4d. Are you sure you want to continue connecting (yes/no)? ``` 该段话的内容是,无法确定host主机的真实性,只知道它的公钥指纹,是否继续连接 假如经过风险衡量后,用户决定接收远程主机的公钥 ```bash Are you sure you want to continue connecting (yes/no)? yes ``` 系统会出现一句提示,表示host主机已经得到认可 ```bash Warning: Permanently added 'host,12.18.429.21' (RSA) to the list of known hosts. ``` 然后,会要求输入密码登陆主机 ```bash Password: (enter password) ``` 当远程主机的公钥被接受之后,会被保存在`$HOME/.ssh/know_hosts`中,在下次连接该主机时,会跳过警告部分,直接提示输入密码 ### SSH公钥生成 查看系统是否已经拥有密钥 ```bash cd ~/.ssh ls ``` ### 查看已暂存和未暂存的修改 git diff可以查看你具体修改了什么地方 git diff可以查看尚未暂存的文件更性了什么地方 ```bash git diff diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 8ebb991..643e24f 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -65,7 +65,8 @@ branch directly, things can get messy. Please include a nice description of your changes when you submit your PR; if we have to read the whole diff to figure out why you're contributing in the first place, you're less likely to get feedback and have your change -merged in. +merged in. Also, split your changes into comprehensive chunks if your patch is +longer than a dozen lines. If you are starting to work on a particular area, feel free to submit a PR that highlights your work in progress (and note in the PR title that it's ``` 此命令比较的是但前未暂存文件和暂存区文件之间的差异 若要查看已经暂存的将要添加到下次提交的内容可以用`git diff --staged`命令 ```bash $ git diff --staged diff --git a/README b/README new file mode 100644 index 0000000..03902a1 --- /dev/null +++ b/README @@ -0,0 +1 @@ +My Project ``` ### 忽略文件 一般情况下,我们总有一些文件不希望纳入版本控制git的管理,也不希望他们出现在 未追踪的文件列表。 在这种情况下,我们可以创建一个名为`.gitignore`的文件,列出要忽略的文件的模式 文件`.gitignore`的格式规范如下: - 所有空行或者以 # 开头的行都会被 Git 忽略。 - 可以使用标准的 glob 模式匹配,它会递归地应用在整个工作区中。 - 匹配模式可以以(/)开头防止递归。 - 匹配模式可以以(/)结尾指定目录。 - 要忽略指定模式以外的文件或目录,可以在模式前加上叹号(!)取反 ### 跳过使用暂存区域 Git提供了一个跳过使用暂存区的方式,只要在提交的时候,给`git commit`加上`-a` 选项,git就会自动把所有已经跟踪过且修改过的文件一并提交。从而跳过`git add`步骤 ```bash $ git status On branch master Your branch is up-to-date with 'origin/master'. Changes not staged for commit: (use "git add ..." to update what will be committed) (use "git checkout -- ..." to discard changes in working directory) modified: CONTRIBUTING.md no changes added to commit (use "git add" and/or "git commit -a") $ git commit -a -m 'added new benchmarks' [master 83e38c7] added new benchmarks 1 file changed, 5 insertions(+), 0 deletions(-) ``` ### 移除文件 要从Git中移除某个文件,就必须从已追踪清单中(暂存区)移除,然后再提交 可以用`git rm`命令来完成此项工作,并连带删除工作目录中指定的文件。 ```bash $ rm PROJECTS.md $ git status On branch master Your branch is up-to-date with 'origin/master'. Changes not staged for commit: (use "git add/rm ..." to update what will be committed) (use "git checkout -- ..." to discard changes in working directory) deleted: PROJECTS.md no changes added to commit (use "git add" and/or "git commit -a") ``` ```bash $ git rm PROJECTS.md rm 'PROJECTS.md' $ git status On branch master Your branch is up-to-date with 'origin/master'. Changes to be committed: (use "git reset HEAD ..." to unstage) deleted: PROJECTS.md ``` 下次提交时,该文件就不会纳入版本管理了 另一种情况是,我们想把文件从git仓库中删除,但希望保留工作目录的文件 可以使用`git rm --cached README`命令 ### 远程库修改的拉取 拉取远程仓库文件,不会修改当前本地主分支 ```bash git fetch origin master ``` 将远程仓库文件合并到本地主分支 ```bash git checkout master git merge origin/master ``` pull相当于fetch+merge ### 解决冲突测试