一些git指令
详细参考教程:https://blog.csdn.net/wangrenbao123/article/details/55511461
cd D:
(进入D盘)cd www
(进入www文件)mkdir test
(在www里面创建名称为test的文件)cd testgit
(进入testgit文件)pwd
(用于显示当前目录)git init
(通过命令把这个目录变成git可以管理的仓库,此时testgit文件里面会新增一个.git文件如果看不到可以点击查看隐藏文件看到)
如果要将某文件比如readme.txt放进仓库中可以输入:
git add readme.txt
但可能会出现这样的提示:
fatal: pathspec 'readme.txt' did not match any files
这说明在文件夹里并没有readme.txt这个文件
去库的文件夹下创建好readme.txt后,再次输入:
git add readme.txt
成功
git status (来查看是否还有文件未提交)
Git指令用法
usage: git commit [] [–] …
-q, --quiet suppress summary after successful commit
-v, --verbose show diff in commit message template
Commit message options
-F, --file <file> read message from file
--author <author> override author for commit
--date <date> override date for commit
-m, --message <message>
commit message
-c, --reedit-message <commit>
reuse and edit message from specified commit
-C, --reuse-message <commit>
reuse message from specified commit
--fixup <commit> use autosquash formatted message to fixup specified commit
--squash <commit> use autosquash formatted message to squash specified commit
--reset-author the commit is authored by me now (used with -C/-c/--amend)
-s, --signoff add Signed-off-by:
-t, --template <file>
use specified template file
-e, --edit force edit of commit
--cleanup <default> how to strip spaces and #comments from message
--status include status in commit message template
-S, --gpg-sign[=<key-id>]
GPG sign commit
Commit contents options
-a, --all commit all changed files
-i, --include add specified files to index for commit
--interactive interactively add files
-p, --patch interactively add changes
-o, --only commit only specified files
-n, --no-verify bypass pre-commit and commit-msg hooks
--dry-run show what would be committed
--short show status concisely
--branch show branch information
--ahead-behind compute full ahead/behind values (EXPERIMENTAL)
--porcelain machine-readable output
--long show status in long format (default)
-z, --null terminate entries with NUL
--amend amend previous commit
--no-post-rewrite bypass post-rewrite hook
-u, --untracked-files[=<mode>]
show untracked files, optional modes: all, normal, no. (Default: all)
git warning: LF will be replaced by CRLF in
解决办法:
输入如下指令:
git config core.autocrlf false
git commit -m
“修改操作记录” (用来提交修改记录)
git reset --hard
版本号 (用来恢复文件到之前的某个版本)
git reflog
(查看之前的版本号)
如果所做的修改操作并没有git修改记录则可以直接撤销修改操作,撤销指令为:git checkout -- readme.txt
工作区:就是你在电脑上看到的目录,比如目录下testgit里的文件(.git隐藏目录版本库除外)。或者以后需要再新建的目录文件等等都属于工作区范畴。
版本库(Repository):工作区有一个隐藏目录.git,这个不属于工作区,这是版本库。其中版本库里面存了很多东西,其中最重要的就是stage(暂存区),还有Git为我们自动创建了第一个分支master,以及指向master的一个指针HEAD。
我们前面说过使用Git提交文件到版本库有两步:
第一步:是使用 git add 把文件添加进去,实际上就是把文件添加到暂存区。
第二步:使用git commit提交更改,实际上就是把暂存区的所有内容提交到当前分支上。
rm b.txt
(文件名目录下直接删掉文件)
git checkout -- b.txt
(恢复删除的文件)
增加SSH Key(参考链接)
$ssh-keygen -t rsa -C "[email protected]"
Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/you/.ssh/id_rsa): [Press enter]
Enter passphrase (empty for no passphrase): [Type a passphrase]
Enter same passphrase again: [Type passphrase again]
运行如下命令将公钥内容粘贴到粘贴板中:
clip < ~/.ssh/id_rsa.pub
完成上面步骤以后登录GitHub,依次进入Your Profile–>Edit Profile->SSH and GPG keys
输入任意的名称,粘贴刚刚复制的秘钥,最后add ssh key
,完成。
之后创建远程Git仓库,步骤:点击create a new reposiry
输入名称即可。
本地更新后提交到远程仓库的指令:git push origin master
查看分支:git branch
创建分支:git branch name
切换分支:git checkout name
创建+切换分支:git checkout –b name
合并某分支到当前分支:git merge name
删除分支:git branch –d name