赞
踩
git remote add [远程名称] [远程仓库链接] //关联(添加)远程仓库;
git remote add origin http://gitlab...
第一步:查看分支在哪里,是自己的吗,添加暂存区,添加到仓库。(建议先将最新分支推送一下到git)
git branch -v
git add .
git commit -m "暂存区提交本地 仓库叙述"
第二步: ( 假设 master 是主分支, xss 是我自己的分支 )
查看分支, 切换分支到主分支, 查看分支, 拉取最新分支代码, 切换回自己分支, 查看分支, 合并分支
git branch -v
git checkout master
git branh -v
git pull
git checkout xss
git branch -v
git merge master
- <html>
-
- <!-- 推送 -->
- git add xxx //添加文件到暂存区
- git commit -m “xx” //从暂存区提交到本地仓库
- git push origin xss //第一次push需要:(自己分支名比如xss)
-
-
- <!-- 拉取自己分支 -->
- git pull origin xss //origin远程仓库,xss远程分支名称
-
-
- <!-- 拉取 仓库代码 -->
- git clone 远程仓库地址
- // 第一次提交代码会让输入账号密码的, 一次就好
-
-
- <!--
- 因此第一次在电脑上使用时需要初始化git(账号密码),
- 以后再使用Git操作,无需初始化,直接进行Git其他操作
- -->
- git config --global user.name "用户名"
- git config --global user.email "admin@admin.com"
-
- <!-- 三板斧: 确保当前工作环境无任何文件提交 -->
- git status 未提交更改保存到一个临时的栈中,以便稍后恢复这些修改
- git pull 更新当前分支xss代码
- git status pop 从临时栈中恢复到工作目录
- ...后续可以执行 推送 三步骤了
-
-
-
- <!-- 分支:一个人一般只创建一个分支 -->
- git branch 分支名 //创建分支
-
-
- git branch -v //查看分支 , *表示当前所在分支
- git branch -r //显示所有分支名称
- git checkout 分支名 //切换分支
-
- git merge 其他分支 //此分支 合并其他分支,建议是合并主master分支
-
-
-
-
-
-
-
-
-
-
- <!-- --> 拉取最新master 合并到自己分支:
- <!-- -->
- <!-- --> 这个要慎重啊:适用于自己能力强,一次解决所有分支合并,建议一个个的合并
-
- <!--
- 解决:git pull后拉下来的代码不是远程仓库中最新的,
- 记得自己代码先push到自己分支,要不克隆的是远程仓库master的,
- 会丢失自己代码
- -->
- git fetch --all
- git reset --hard origin/master // origin/master 是你所需要更新的分支
- git pull
- <!-- 它就可以取到本地分支的每个分支的最新内容。 -->
- for i in `git branch | sed 's/^.//'`; do git checkout $i ; git pull; done
- </html>

使用 git stash
命令将当前分支上的未提交更改保存到暂存区中:
使用 git pull
命令拉取远程分支的最新代码并进行更新:
git pull
使用 git stash pop
命令将之前保存的更改从暂存区中恢复到工作目录:
git stash pop
创建:
gitee里创建项目:::(或者:git init //初始化仓库(只执行一次)。这个麻烦,直接不用)
文件:克隆仓库 => 上传文件
git clone 新建的仓库地址
git add .
git commit -m "提示信息"
git push origin master //分支看主分支还是自己分支(提交)
git push origin xss // 报错
error: failed to push some refs to ‘远程仓库地址’
// 复位
git pull --rebase origin master
// 正常上传了
git push -u origin xss
git pull // 报错
git warning: redirecting to https://xxx.xxx.xxxx/xxx/xxx.git/
// 是服务端的一种安全提醒,需要修改配置从新和远程仓库建立连接就可以了
//第一步:删除远程仓库 origin 地址
git remote remove origin
//第二步:重新绑定远程仓库 origin 地址
git remote add origin https://igit.**.com/**/**.git/
git checkout xss // 报错
【Git-error】Your local changes to the following files would be overwritten by checkout
// 分支更改了, 未提交. 未跟进
1. 最简单的, 直接提交, 但是提交次数多, 提交历史会混乱 (推荐)
2. git stash
- git stash
-
- 保存当前分支修改进度,将工作区和暂存区恢复到修改之前
-
-
- git stash save "当前修改的说明"
-
- 此命令的作用同 git stash 命令,不过可以添加一个说明,
- 用来标识(解释)当前工作修改,方便恢复
-
-
- git stash list
-
- 显示所有保存的工作进度列表,编号越小代表保存进度的时间越近
-
-
- git stash pop stash@{num}
-
- 恢复之前保存的工作进度到当前工作区,此命令的 stash@{num} 是可选项,
- 在多个工作进度中可以选择恢复,
- 不带此项则默认恢复最近的一次进度相当于 git stash pop stash@{0}
-
-
- git stash clear
-
- 删除所有保存的工作进度
-
-
-
-
- 使用问题:git stash pop stash@{0} 报错,如下
-
- error: unknown switch `e'
- usage: git stash apply [--index] [-q|--quiet] [<stash>]
-
- -q, --quiet be quiet, only report errors
- --index attempt to recreate the index
- 这种问题是因为VSCode中,花括号在 powershell 中
- 被认为是代码块执行标识符,若想正常使用,
- 可用反引号 `进行转义:stash@`{0’},如下:
- git stash pop stash@`{0`}
- 或者切换终端类型

git stash 用法:
3. 强制分支切换:
git checkout -f xss
1. 复制想要回退的 提交 id
右键选择 git bash here
git log 查看提交历史
去到 gitlab 托管平台 点击 history
进入 复制历史
2. 本地代码到指定版本 git reset --hard commitId
eg:
git reset --hard fdsf164d0516cd0bc56f79eb94cf55056d7b
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。