Home > php教程 > PHP开发 > body text

Git rollback of remote version

高洛峰
Release: 2016-11-22 17:24:11
Original
1451 people have browsed it

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



Related labels:
git
source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!