search
Homephp教程PHP开发Git rollback of remote version
Git rollback of remote versionNov 22, 2016 pm 05:24 PM
git

1. The beginning of the story

The code under the remote master branch was accidentally submitted with a lot of junk code or the project was deleted. I wanted to roll back to a previous version and delete the commit log. what to do? The scenario is as shown in the picture:

Git rollback of remote version

The scenario is very simple. My boss uploaded a file and I deleted it. There is a way to push the file again, but you don’t want him to see the comment in the picture (ps: this way I won’t be fired). The code to implement the above scenario is as follows:

vim A.txt

git add .

git commit -a -m "add A.txt"

git push

rm A.txt

git commit -a -m "I deleted the boss's stuff"

git push

————–Separating line————–

What should a confused newbie do? what to do? what to do?

The submission pushed to the remote cannot be modified by default, but it must be modified:

git push -f

2. Solution

2.1 Workspace, staging area, local repository & remote Version library

No pic say 78. . .

Git rollback of remote version

》》Workspace: It is the directory where we operate

》》Staging area: a snapshot of the operating directory

》》Local repository: the essence of Git, everyone is the central warehouse. That is to say, the benefits of Git distribution are naturally compared to the centralized version like SVN

》》Remote version library: a central warehouse like Github can achieve sharing.

Commonly used operations are also shown in the picture, which is self-evident.

2.2 Practical solution

Talk is cheap, Show me the code or money~ The code is as follows:

git log

git reset --soft ${commit-id}

git stash

git push -f

The detailed explanation is as follows:

Line 1: git log View the commit history, and then find the version to be rolled back. The history is as follows,

commit 84686b426c3a8a3d569ae56b6788278c10b27e5b

Author: JeffLi1993

Date: Fri Apr 8 19:1 1:32 2016 +0800


I deleted my boss’s stuff


commit 72bd6304c3c6e1cb7034114db1dd1b8376a6283a

Author: JeffLi1993

Date: Fri Apr 8 19:05:23 2016 +0800


add A.txt

The version we want to roll back to That is: 72bd6304c3c6e1cb7034114db1dd1b8376a6283a

Line 2: git reset –soft 72bd6304c3c6e1cb7034114db1dd1b8376a6283a

Undo the previous version Modify and return to the temporary storage area (I don’t know how to look at beautiful pictures~). The difference between soft and hard parameters is that hard modification records are lost, while soft will retain modification records.

Line 3: Temporarily saved for safety reasons.

Line 4: git push -f

Push the local master to the remote repository, -f forces overwriting.

3. Summary

git reset rolls back to a certain version
git push -f forces push overwrite



Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
github是什么github是什么Mar 24, 2023 pm 05:46 PM

​GitHub是一个面向开源及私有软件项目的托管平台,可以让开发者们在这里托管自己的代码,并进行版本控制。GitHub主打的是开源项目与协作,通过这个平台上的开源项目,开发者们可以查看其他开发者的项目源代码,并进行交流和学习。

git中push -u是什么意思git中push -u是什么意思Jul 01, 2022 am 10:36 AM

在git中,“push -u”的意思是将本地的分支版本上传到远程合并,并且记录push到远程分支的默认值;当添加“-u”参数时,表示下次继续push的这个远端分支的时候推送命令就可以简写成“git push”。

git的pack文件有什么用git的pack文件有什么用Jun 30, 2022 pm 05:41 PM

在git中,pack文件可以有效的使用磁盘缓存,并且为常用命令读取最近引用的对象提供访问模式;git会将多个指定的对象打包成一个成为包文件(packfile)的二进制文件,用于节省空间和提高效率。

如何在GitLab上进行第一次登录并更改密码如何在GitLab上进行第一次登录并更改密码Mar 24, 2023 pm 05:46 PM

GitLab是一种基于Web的Git版本控制库管理软件,旨在帮助开发团队更好地协同工作,提高工作效率。当您第一次登录GitLab时,系统会提示您要更改初始密码以确保账户安全。本文将为大家介绍如何在GitLab上进行第一次登录并更改密码。

git中pull失败了怎么办git中pull失败了怎么办Jun 30, 2022 pm 04:47 PM

git中pull失败的解决方法:1、利用“git reset --hard”强制覆盖掉自己的本地修改;2、利用“git stash”推送一个新的储藏,拉取之后利用“git stash pop”将修改保存到暂存区;3、若依然出现问题,则将文件保存到暂存区并提交注释即可。

git分支能改名字吗git分支能改名字吗Jun 16, 2022 pm 05:55 PM

git分支能改名字。改名方法:1、利用git中的branch命令修改本地分支的名称,语法为“git branch -m 旧名字 新名字”;2、利用“git push origin 新名字”命令,在删除远程分支之后将改名后的本地分支推送到远程;3、利用IDEA直接操作修改分支名称即可。

用三行代码使你的git提交记录变干净用三行代码使你的git提交记录变干净Feb 28, 2023 pm 04:19 PM

本篇文章给大家带来了关于git的相关知识,其中主要跟大家聊一聊怎么让你的git记录保持整洁,感兴趣的朋友下面一起来看一下吧,希望对大家有帮助。

git怎么删除某个分支git怎么删除某个分支Jun 24, 2022 am 11:11 AM

git删除某个分支的方法:1、利用“git branch --delete dev”命令删除本地分支;2、利用“git push origin --delete branch”命令删除远程分支;3、利用“git branch --delete --remotes”命令删除追踪分支。

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function