GitLab回滚代码

936 阅读2分钟

本文已参与「新人创作礼」活动,一起开启掘金创作之路。

GitLab 之 代码回滚

因某种未知原因误操作git将新代码被老代码覆盖并提交代码。导致拉取代码后无法正常运行项目需要代码回滚

git bash

在项目所在的目录右键打开git bash命令窗口

确定分支

# 查看本地分支
git branch
# 查看远程分支
git branch -a
# 切换dev分支
git checkout -b dev origin/dev

查看提交记录

git log

commit为提交记录id,找到需要回滚的提交记录的commit 1.png

执行命令进行回滚

git reset --hard d15af74915143ae324c011d6e0d11f76759bb901

执行命令同步至远程分支

git push -f

远程仓库相关命令

查看远程仓库:$ git remote -v
添加远程仓库:$ git remote add [name] [url]
删除远程仓库:$ git remote rm [name]
修改远程仓库:$ git remote set-url --push[name][newUrl]
拉取远程仓库:$ git pull [remoteName] [localBranchName]
推送远程仓库:$ git push [remoteName] [localBranchName]

分支(branch)操作相关命令

查看本地分支:$ git branch
查看远程分支:$ git branch -r
创建本地分支:$ git branch [name] ----注意新分支创建后不会自动切换为当前分支
切换分支:$ git checkout [name]
创建新分支并立即切换到新分支:$ git checkout -b [name]
删除分支:$ git branch -d [name] ---- -d选项只能删除已经参与了合并的分支,对于未有合并的分支是无法删除的。如果想强制删除一个分支,可以使用-D选项
合并分支:$ git merge [name] ----将名称为[name]的分支与当前分支合并
创建远程分支(本地分支push到远程):$ git push origin [name]
删除远程分支:$ git push origin :heads/[name]

.gitignore配置

# See http://help.github.com/ignore-files/ for more about ignoring files.

# compiled output
dist

# dependencies
node_modules
package-lock.json

# local env files
.env.local
.env.*.local

# Log files
.pnpm-debug.log*
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# IDEs and editors
/.idea
.project
.classpath
.c9/
*.launch
.settings/
*.sublime-workspace

# IDE - VSCode
# .vscode/*
# !.vscode/settings.json
# !.vscode/extensions.json
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?

# System Files
.DS_Store
Thumbs.db
.npmrc
.cache

.gitattributes 配置

*.html text eol=lf
*.vue text eol=lf
*.css text eol=lf
*.js text eol=lf
*.ts text eol=lf
*.scss text eol=lf
*.vue text eol=lf
*.hbs text eol=lf
*.sh text eol=lf
*.md text eol=lf
*.json text eol=lf
*.yml text eol=lf
.browserslistrc text eol=lf
.editorconfig text eol=lf
.eslintignore text eol=lf
.gitattributes text eol=lf
LICENSE text eol=lf
*.conf  text eol=lf

继续学习

废话只说一句:码字不易求个👍,收藏 === 学会,快行动起来吧!🙇‍🙇‍🙇‍。

# Vite+Vue3+TypeScript+Element (一) 搭建企业级轻量框架实践