Git学习使用
Git的定义中,共有四个分区

- 
学习链接: B站:https://www.bilibili.com/video/BV1tf4y1e7yt?p=1
- 
从远程仓库下载项目 git clone https://github.com/wsdassssss/Github-test.git
- 
将修改后文件加到缓存区中 git add record.txt
- 
将缓存区文件提交到本地仓库 git commit -m "first change"
- 
将本地仓库文件推送到远程仓库 git push
- 
从远程仓库拉取 git pull
- 
修改后,未提交到缓存区,恢复原文件 git restore record.txt
- 
查看工作区文件和缓存区文件内容差异 git diff
 git diff --stat 显示摘要
- 
查看文件变化 git status 
- 
取消上一次git add 
git reset HEAD
- 
查看提交历史 git log 
- 
删除 git rm <file> git rm --cached test3.txt #将test3.txt从缓存区删除 git rm -f test3.txt #将test3.txt从缓存区和工作区删除 
- 
新建仓库 git init 
- 
提交第一个版本到版本库,第一代,v1.0 git add first.txt git commit -m 'v1.0' 
- 
提交第二个版本到版本库,新增功能,v2.0 git add second.txt git commit -m 'v2.0' 
- 
提交第三个版本到版本库,新增功能v2.2,但需要回退到v2.0,再回退到V2.2 #提交版本v2.1 git add . git commit -m 'v2.2' #回退到V2.0 git log #获取v2.0的版本标识 git reset --hard 9c7c82b0880e30a430bb506d9098d49362e8a6fa #执行成功,回退到v2.0,git log 无V2.2记录 再回到V2.2git reflog 
 git reset --hard b2d80c3
- 
简略图 ![image-20201227222054748]() 
- 
修改文件后,放弃修改,在git add 之前 git checkout -- first.txt 
- 
git add之后想要回退文件 git reset HEAD 
- 
分支 #新建功能分支 git branch func1 #新建func1分支 git checkout fun1 #切换到func1分支 nano first.txt #添加 3.house working git add 'first.txt' git commit -m 'new func1 branch' git checkout main #分支每次切换到main之前要先commit,否则文件内容会停在前面分支 修复BUG分支git branch bug1 
 git checkout func1
 nano first.txt #修改 2.house--bug
 git add .
 git commit -m 'bug finish'
 git checkout mainmain分支merge分支bug1git merge bug1 #first.txt line2: 2.drink--bug 合并bug分支完成功能func1完成,合并分支func1main first.txt1.phoyo 
 2.drink-bugfunc1 first.txt1.phoyo 
 2.drink
 3.housegit merge func1 会引发冲突,因为main分支line2和func2分支line2不同,需要手动处理,再进行提交示例如下图所示![image-20201228002303518]() 
- 
Github git remote add test[name] *************************.git #添加远程仓库 git push -u test[name] main[branch] 本地仓库和远程仓库是独立仓库,关联需要先执行git pull test main --allow-unrelated-histories 
 git push test main推送func1分支git push -u github_test[name] func1[branch] 从远程仓库下载git clone ***********************.git 切换分支git checkout func1 修改first.txtADD: 4.food git add first.txt 
 git commit -m '4.fodd'
 git push再去网页查看,func1分支已经更新
- 
Git rebase,让提交更加简洁 git rebase -i HEAD~3 #合并最近三次的commit 
- 
Git log git log --graph git log --graph --pretty=format:"%h %s" 
- 
git init git remote add qt_work **.git git pull qt_work git pull 
 
                     
                    
                 
                    
                


 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号