Git使用01

时间:2023-03-09 18:28:58
Git使用01

git

工作区:当前编辑的区域

缓存区:add 之后的区域

本地仓库:commit之后的区域

远程仓库:远程的区域

git init 初始化

git status 查看git的状态

git add 将文件放到缓存区

git commit -m 将缓存区的内容提交到本地仓库

git config --global user.email 'adf@qq.com'设置用户的邮箱

git config --global user.name "xxx" 设置用户的用户名

git config --global --unset user.email 删除用户的邮箱

git config --global --unset user.name 删除用户的用户名

git log 查看当前版本之前提交记录

git reset --hard hash值 回退到之前某次提交的地方 慎用

git reflog 查看所有的提交记录

git checkout filename 将指定文件回退到最近一次commit的地方,只对工作区做修改,缓存区不变 慎用

git reset HEAD filename 将指定文件从缓存去拉取到工作区,不会覆盖原来的文件

git diff 对比缓存区和工作区的区别

git diff --cached 对比缓存区和本地仓库的区别

github

码云

因为线上版本跟本地版本库不一致,本地版本比线上新

! [rejected] master -> master (non-fast-forward) error: failed to push some refs to 'https://github.com/417685417/cw.git' hint: Updates were rejected because the tip of your current branch is behind hint: its remote counterpart. Integrate the remote changes (e.g.                                          hint: 'git pull ...') before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details.

冲突:同时修改了同一个文件的同一个位置,冲突自己解决

Auto-merging templates/index.html CONFLICT (content): Merge conflict in templates/index.html Automatic merge failed; fix conflicts and then commit the result.

因为没有权限

Logon failed, use ctrl+c to cancel basic credential prompt. remote: Permission to 417685417/cw.git denied to WuPeiqi. fatal: unable to access 'https://github.com/417685417/cw.git/': The requested URL returned error: 403

stash

git remote add origin https://github.com/417685417/cw.git 添加别名

git clone https://url.git

git push origin master 将本地的文件上传到远程仓库

git pull origin master 将远程仓库的文件拉取到本地

git stash 创建一个快照

git stash pop 取出快照并删除快照记录

git stash list 查看快照记录

git stash drop name 删除快照

git stash apply name 取出快照