Git(读音为/gɪt/。)是一个开源的分布式版本控制系统,可以有效、高速的处理从很小到非常大的项目版本管理。 [1] Git 是 Linus Torvalds 为了帮助管理 Linux 内核开发而开发的一个开放源码的版本控制软件。
1.初始化配置
生成SSH公钥
1 | ssh-keygen -t rsa -C <[email protected]>( 你的邮箱) |
1 | ssh-keygen -t rsa -b 4096 -C <[email protected]> |
公钥的存储目录
C:\Users\Fly.ssh
打开 id_rsa.pub
,打开此文件,复制其内容,粘贴到网站的指定位置
验证一下是否配置成功
1 | ssh -T [email protected] |
2.设置用户名和邮箱
1 | git config --global user.name "name" |
3.克隆仓库
1 | git clone [email protected]:speFigure/TestGit.git |
默认路径 C:\Users\Fly</code>
4.初始化仓库
进入到项目文件夹 cd 目录名
1 | git init |
5.添加文件
可以在项目目录添加一个文件,然后进行上传操作
1 | git add . |
预上传新文件并添加备注内容
1 | git commit -m "add git.md" //备注内容 |
开始进行上传
1 | git push origin master |
6.其他
查看本地仓库和远程仓库的对应关系
1 | git remote -v |
设置本地仓库和远程仓库的对应关系
1 | git remote add orign [email protected]:speFigure/TestGit.git |
查看状态
1 | git status |
取消以缓存内容
如果一个文件已经add到暂存区,还没有 commit
1 | git reset HEAD //回退到当前版本(在Git中,用HEAD表示当前版本,上一个版本就是HEAD^,上上一个版本就是HEAD^^,当然往上100个版本写100个^比较容易数不过来,所以写成HEAD~100); |
撤销修改
1 | git checkout -- filename |
查看历史记录
1 | git log |
1 | git reflog //详细信息 |
版本回退
1 | git reset --hard HEAD //上一个版本就是HEAD^,上上一个版本就是HEAD^^,当然往上100个版本写100个^比较容易数不过来,所以写成HEAD~100。 |
加标签
1 | git tag -a v1.2 9fceb02 |
7.一些问题的处理(我使用时出现的哈哈,记录下📝)
- 问题1
$ git push -u origin master
To [email protected]:xxx/xxx.git
! [rejected] master -> master (fetch first)
error: failed to push some refs to ‘[email protected]:xxx/xxx.git’
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., ‘git pull …’) before pushing again.
hint: See the ‘Note about fast-forwards’ in ‘git push –help’ for details.
处理方法
1 | git pull --rebase origin master |
- 问题2
To [email protected]:yangzhi/hello.git
! [rejected] master -> master (fetch first)
error: failed to push some refs to ‘ ‘
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushin
hint: to the same ref. You may want to first merge the remote changes (e.g.
hint: ‘git pull’) before pushing again.
hint: See the ‘Note about fast-forwards’ in ‘git push –help’ for details.
处理方法
1 | git push -f |
参考文献
>Git命令来自网络💻
>如有错误❌还请指出🙂