赞
踩
下载Git https://git-scm.com/download/win
(官网下载Git太慢的解决方法: https://npm.taobao.org/mirrors/git-for-windows/)
下载完cmd中输入 ,如果放回版本号,那么安装ok
git --version
PS:文件默认在C中的.ssh文件中的id_rsa.pub文件(用记事本开打即可)
https://gitee.com/profile/sshkeys
1.创建页面只需填 仓库名称 和 仓库介绍就好了,名称必须是英文
2.创建完是这个页面
1. Git 全局设置:
- git config --global user.name "仓库名字"
- git config --global user.email "仓库邮箱"
2. 根据上面的提示, 进入要上传的项目, 执行: (和线上仓库连接)
git remote add origin <线上仓库地址>
3. 然后执行提交代码
4. 输入码云账号密码
5. 提示完成
git init
1. 在码云项目中点击下载/克隆,选中SSH,复制链接
2. 打开cmd
- # 文件要放哪你就去哪,这里是桌面
- cd Desktop
-
- git clone <线上仓库地址>
Cloning into 'travel'...
remote: Enumerating objects: 4, done.
remote: Counting objects: 100% (4/4), done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 4 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (4/4), done. //表示项目已经完成下载
git clone -b <分支名称> <线上仓库地址>
1. 第一次更新需要将本地仓库与码云远程仓库进行关联
- git remote add origin <线上仓库地址>
- git pull
(第一次才要已上操作,往后 git pull 就可以了)
1.第一次提交需要将本地仓库与码云远程仓库进行关联
- git remote add origin <线上仓库地址>
-
- # "."表示所有目录,也可跟目录名或文件名
- git add .
-
- # 将目录提交到本地并加版本说明
- git commit -m <说明>
-
- # 将目录提交到远程仓库的master分支中
- git push -u origin master
第一次才要已上操作,往后 ↓
- git add .
- git commit -m <说明>
- git push
git status
// 它会返回你在那个分支,是否干净,代码是否和线上同
On branch master
nothing to commit, working directory clean
1. 新建分支 ( 新建后它会自己切换到这个新分支 )
git checkout -b <分支名字>
2. 查看分支
- # 查看本地分支 ( 带 * 的就是当前的分支 )
- git branch
-
- # 查看线上分支
- git branch -r
3. 切换分支
git checkout <分支名字>
4. 合并分支
git merge <分支名字>
5. 提交到指定分支
git push origin <分支名字>
6. 拉取到指定分支
git pull origin <分支名字>
7. 同步线上分支(前提本地没有这个分支)
git checkout -b <本地分支名字> origin/<线上分支名字>
- # 查看当前分支
- git branch
- # 查看当前分支的状态
- git status
-
- # 提交新分支
- git add .
- git commit -m "新分支"
- git push origin <分支名字>
-
- # 合并分支
- # 切换回主分支
- git checkout master
- # 合并刚才提交的分支
- git merge <刚才提交的分支>
- # 提交代码主分支代码
- git push

本地分支删除
*如果你还在这个分支上,那么 Git 是不允许你删除这个分支的。所以,请记得退出分支
git branch -d <分支名称>
远程分支删除
git push origin --delete <分支名称>
如果你得到以下错误消息,可能是因为其他人已经删除了这个分支。
error: unable to push to unqualified destination: remoteBranchName The destination refspec neither matches an existing ref on the remote nor begins with refs/, and we are unable to guess a prefix based on the source ref. error: failed to push some refs to 'git@repository_name'
使用以下命令同步在线分支列表:(这样,你的分支列表里就不会显示已远程被删除的分支了。)
git fetch -p
- # 进入注释页面,进行修改, 修改好然后按esc键,退出INSERT模式,输入 :wq 退出
- git commit --amend
-
- # 推送
- git push
- # 进入注释页面,进行修改, 修改好然后按esc键,退出INSERT模式,输入 :wq 退出
- git commit --amend
-
- # 强制推送
- git push --force-with-lease origin master
方法一:该命令显示从最近到最远的提交日志。每一次提交都有对应的 commit id 和 commit message
git log
方法二: 简略的提交日志( 常用 )
git log --oneline
前面黄色的就是id,最新的版本在最上面
方法三: 查看命令操作的历史
git reflog
git reset --hard id
git push origin HEAD --force
git remote set-url origin <新名称>
重新生成SSH公钥,在过来码云配置即可
1. 改git本地账户(windows)
(一)进入控制面板
(二)选择用户账户
(三)选择管理你的凭据
(四)选择Windows凭据
(五)选择git保存的用户信息
(六)选择编辑或者进行删除操作
2. 修改git提交账户
打开git的命令控制窗口, 查看邮箱和用户名是不是你的
git config --list
修改git提交的email
git config --global user.email test@test.com
修改提交的git的user.name
git config --global user.name test
报错内容:
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'https://gitee.com/.......'
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 origin master
- git push origin master
2. 使用强制push的方法,但是这会使远程修改丢失,一般是不可取的,尤其是多人协作开发的时候
git push origin master -f
1. 把隐藏文件显示
2. 确保分支名一致后,打开项目目录下的 git/config
文件。
3.在 [remote "origin"] 在配置个url即可
- [core]
- repositoryformatversion = 0
- filemode = false
- bare = false
- logallrefupdates = true
- symlinks = false
- ignorecase = true
- [remote "origin"]
- url = 仓库一地址
- url = 仓库二地址
- fetch = +refs/heads/*:refs/remotes/origin/*
- [branch "master"]
- remote = origin
- merge = refs/heads/master
1、删除命令:
git rm -r --cached <文件名>
2、在add推上去
find . -name ".git" | xargs rm -Rf
CLS
- // 先转到对应的盘
- 盘名字:
-
- // 跳转到对应路径
- cd 对应的文件路径
cd desktop
- runas /user:用户名 cmd
- // 然后输入密码
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。