当前位置:   article > 正文

git 命令:合并代码, 基本命令,快速创建git项目, error报错处理, gitlab版本回退_代码合并

代码合并

拉取最新master 合并到自己分支:

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

SSS:::基本命令:

  1. <html>
  2. <!-- 推送 -->
  3. git add xxx //添加文件到暂存区
  4. git commit -m “xx” //从暂存区提交到本地仓库
  5. git push origin xss //第一次push需要:(自己分支名比如xss)
  6. <!-- 拉取自己分支 -->
  7. git pull origin xss //origin远程仓库,xss远程分支名称
  8. <!-- 拉取 仓库代码 -->
  9. git clone 远程仓库地址
  10. // 第一次提交代码会让输入账号密码的, 一次就好
  11. <!--
  12. 因此第一次在电脑上使用时需要初始化git(账号密码),
  13. 以后再使用Git操作,无需初始化,直接进行Git其他操作
  14. -->
  15. git config --global user.name "用户名"
  16. git config --global user.email "admin@admin.com"
  17. <!-- 三板斧: 确保当前工作环境无任何文件提交 -->
  18. git status 未提交更改保存到一个临时的栈中,以便稍后恢复这些修改
  19. git pull 更新当前分支xss代码
  20. git status pop 从临时栈中恢复到工作目录
  21. ...后续可以执行 推送 三步骤了
  22. <!-- 分支:一个人一般只创建一个分支 -->
  23. git branch 分支名 //创建分支
  24. git branch -v //查看分支 , *表示当前所在分支
  25. git branch -r //显示所有分支名称
  26. git checkout 分支名 //切换分支
  27. git merge 其他分支 //此分支 合并其他分支,建议是合并主master分支
  28. <!-- --> 拉取最新master 合并到自己分支:
  29. <!-- -->
  30. <!-- --> 这个要慎重啊:适用于自己能力强,一次解决所有分支合并,建议一个个的合并
  31. <!--
  32. 解决:git pull后拉下来的代码不是远程仓库中最新的,
  33. 记得自己代码先push到自己分支,要不克隆的是远程仓库master的,
  34. 会丢失自己代码
  35. -->
  36. git fetch --all
  37. git reset --hard origin/master // origin/master 是你所需要更新的分支
  38. git pull
  39. <!-- 它就可以取到本地分支的每个分支的最新内容。 -->
  40. for i in `git branch | sed 's/^.//'`; do git checkout $i ; git pull; done
  41. </html>

报错警告: 表示需要先拉取最新代码:  三板斧解决

  1. 使用 git stash 命令将当前分支上的未提交更改保存到暂存区中

    git stash
  2. 使用 git pull 命令拉取远程分支的最新代码并进行更新

    git pull
  3. 使用 git stash pop 命令将之前保存的更改从暂存区中恢复到工作目录

    git stash pop

快速创建项目上传文件:

创建:

gitee里创建项目:::(或者:git init    //初始化仓库(只执行一次)。这个麻烦,直接不用

文件:克隆仓库 => 上传文件

git clone 新建的仓库地址

git add .

git commit -m "提示信息"

git push origin master               //分支看主分支还是自己分支(提交)

error:

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

  1. git stash
  2. 保存当前分支修改进度,将工作区和暂存区恢复到修改之前
  3. git stash save "当前修改的说明"
  4. 此命令的作用同 git stash 命令,不过可以添加一个说明,
  5. 用来标识(解释)当前工作修改,方便恢复
  6. git stash list
  7. 显示所有保存的工作进度列表,编号越小代表保存进度的时间越近
  8. git stash pop stash@{num}
  9. 恢复之前保存的工作进度到当前工作区,此命令的 stash@{num} 是可选项,
  10. 在多个工作进度中可以选择恢复,
  11. 不带此项则默认恢复最近的一次进度相当于 git stash pop stash@{0}
  12. git stash clear
  13. 删除所有保存的工作进度
  14. 使用问题:git stash pop stash@{0} 报错,如下
  15. error: unknown switch `e'
  16. usage: git stash apply [--index] [-q|--quiet] [<stash>]
  17. -q, --quiet be quiet, only report errors
  18. --index attempt to recreate the index
  19. 这种问题是因为VSCode中,花括号在 powershell 中
  20. 被认为是代码块执行标识符,若想正常使用,
  21. 可用反引号 `进行转义:stash@`{0’},如下:
  22. git stash pop stash@`{0`}
  23. 或者切换终端类型

git stash 用法:

3. 强制分支切换:       

git checkout -f xss

gitlab版本回退

1. 复制想要回退的 提交 id

 右键选择 git bash here

git log 查看提交历史

去到 gitlab 托管平台 点击 history

进入 复制历史

 2. 本地代码到指定版本 git reset --hard commitId

eg:  

git reset --hard  fdsf164d0516cd0bc56f79eb94cf55056d7b

3. 回滚git仓库代码到指定版本:  git push -f
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/盐析白兔/article/detail/863501
推荐阅读
相关标签
  

闽ICP备14008679号