Git 入门

来源:互联网 发布:中国国家标准数据库 编辑:程序博客网 时间:2024/06/16 05:45

根据牛客网https://www.nowcoder.com/courses/2 视频整理的笔记


3.Config
设置用户名、邮箱
git config -global user.name
git config -global user.email
 
4.Init
已经开始的项目 在目录下git init
未开始的项目 gitinit xxx
 
5.Commit
git status
git add
git commit -m “xxx”
 
6.Diff
git diff
git diff --staged
git diff HEAD
git diff --color-words/ --word-diff
git diff --stat 只输出有区别的代码块
 
7.Log
git log
git log --oneline 简短版本
git log --stat
git log --patch  每次提交之间的改变
        
可以组合 私人定制
ex:git log --patch--oneline
gitlog --graph
gitlog --graph --all --decorate --online
 
8.Remove
gitrm file.txt
        
git add -u  保存修改删除
git add .     保存修改添加
git add -A  保存所有
 
git rm -cachedfile.txt 删除不再追踪这个文件/不想让它成为历史的一部分
 
9.Move
git mv header.jpg source/header.jpg    oldpath   new path
git add -A .   .从当前目录开始 无限向下递归
        
查看文件移动历史
git log --stat -- tutorials/intermediate/lesson6 //文件历史在因为文件移动。。结束了?
git log --stat -M -follow - 同上
 
10.特修斯之船
 
11.Ignore

 
touch.gitignore
git add .gitignore
git commit –m”preparing to ignore temporary files”


vim  .gitignore
忽略文件*.log 
忽略文件夹tmp/  
#注释
取消ignore  git ls-files --others --ignored --exclude-standard
 
 
12.Branch
git branch app-startup-scripts 新建branch
git branch -d app-startup-scripts 删除branch
                   如果没有完全合并 换成D 后续还有补充
        
git checkout front-end-fixes 切换
再观看merge一节 详细了解


13.checkout

git checkout -- newname.txt 清理掉最后一次commit的内容
git checkout -b newbranch 新建并转到新分支
        
14.merge
git checkout master
git branch 显示分支
git merge xxx(分支名字)
 
代码内容
                   <<<<<headmaster内容
                   =========冲突开始位置
                   >>>>>>>>>冲突结束位置
        
git merge --abort 从当前分支最后一次提交中清除工作目录 清除stash
git merge --squash all-new-bargraphs  不汇聚历史 想要一个具体分支中的全部commit
        
合并后就可以清除分支了git branch -d cleanup-variables
 
15.network
git remote add origin https://...   创建远程仓库
git remote set-url origin https://...2  url输错了 或者想修改
git remote rm origin 删除
git remote -v             忘记url 显示详细信息
        
git fetch origin 从远程仓库抓取信息 放到远程分支
git pull origin
git push origin
        
16.GUI
 
17.Intro to GitHub
 
18.forking

github拷贝到自己账户下
 
19.pull request
github中
 
20.git reset

重新塑造历史
三种模式 soft mixed(默认) hard
 
与checkout对比 checkout着眼于整个仓库
 
21.reflog
git reflog
git reset --hard xxxx(7位hash码)
 
22.git rebase
保持历史整洁

原创粉丝点击