Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git revert a specific commit avoiding a merge

Tags:

git

I would like to remove a specific commit on a git repository in order to be able to remove a "fix" applied to my software.

There it is an EMC :

#!/bin/bash
rm -rf TEST .git
mkdir TEST
git init
echo "info 1" > TEST/file.txt
git add TEST/
git commit -m "Initial Commit"
echo "info 2" >> TEST/file.txt
git add TEST/
git commit -m "Commit Fix 1 on file"
echo "info 3" >> TEST/file.txt
git add TEST/
git commit -m "Commit Fix 2 sur file"

the result of file.txt will be

info 1
info 2
info 3

And I would like to obtain the file without the line "info 2". The git revert will generate conflict, and I would like to avoid manage those conflicts. That is to say doing like the commit "Commit Fix 1 on file" would have never append.

I tried revert or rebase without any luke, so if you have another idea, I will be glade to have some help.

Sincerely,

like image 531
Brownie Avatar asked Nov 13 '22 21:11

Brownie


1 Answers

To revert a particular commit, you need to identify the hash of the commit, using git log, then use git revert <commit> to create a new commit that removes these changes.

like image 96
Anshu Avatar answered Nov 15 '22 23:11

Anshu