Skip to contentSkip to conversation

Reverting a specific commit

DISCUSSION milindkanchan 3 participants 5 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

Hi All,

I am using git for code management.

I have some query regarding reverting the commit in git.

Can we revert a specific commit in git ?

Eg. One of our X developer has committed the code in master branch last week, after which there were several commits to master branch, now there was an issue with the code committed by X developer and now I need to revert/discard just his commit keeping the other commits done after him as intact.

Can anybody give a solution for this with all the commands.

Thanks & Regard
M.K

Signature · 2 lines
View this message in context: http://git.661346.n2.nabble.com/Reverting-a-specific-commit-tp5561992p5561992.html
Sent from the git mailing list archive at Nabble.com.
#1 lore raw
Quoted 1 line · milindkanchan

Can we revert a specific commit in git ?

   $ git revert <sha1>

for more information:

   $ git revert --help

Pascal.

Signature · 8 lines
--|------------------------------------------------------
--| Pascal Obry                           Team-Ada Member
--| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE
--|------------------------------------------------------
--|              http://www.obry.net
--| "The best way to travel is by means of imagination"
--|
--| gpg --keyserver wwwkeys.pgp.net --recv-key C1082595
#2 lore raw

But will it affect the commits done after that

Signature · 2 lines
View this message in context: http://git.661346.n2.nabble.com/Reverting-a-specific-commit-tp5561992p5562096.html
Sent from the git mailing list archive at Nabble.com.
#3 lore raw
Quoted 2 lines · milindkanchan

But will it affect the commits done after that

No. It is a revert. I will create a new commit that revert the work done for the given commit.

Pascal.

Signature · 8 lines
--|------------------------------------------------------
--| Pascal Obry                           Team-Ada Member
--| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE
--|------------------------------------------------------
--|              http://www.obry.net
--| "The best way to travel is by means of imagination"
--|
--| gpg --keyserver wwwkeys.pgp.net --recv-key C1082595
#4 lore raw
In reply to milindkanchan
Quoted 8 lines · milindkanchan

Hi All,

I am using git for code management.

I have some query regarding reverting the commit in git.

Can we revert a specific commit in git ?

To make a new commit to undo a bad commit:

git revert SHA

where SHA is that long string of numbers and letters associated with each commit. do "git log" to find out what the SHA is.

John