Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

2 questions about working with repository history

Patrick Diviacco March 29, 2016

About working with repository history in Source Tree.

  1. In order to see commits with changes to a specific only, I can filter past commits by file. What if I want to see only commits with changes to specific lines of that file?

  2. If I've understood correctly git revert HEAD~2 reverts the changes in commit Head-2, only but not those ones in commit Head-1. What if I want to revert changes in head-1 too? (without resetting and deleting past commits). Do I maybe need to checkout Head-2 and commit again?

 

2 answers

1 vote
Johannes Kilian
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 29, 2016

At 1.) Haven't seen anything like this in any Git-GUI yet ....

At 2.) Yes you might revert both changes via two 'git revert' commands with commits meantime ... Just to be sure to revert the correct commits, I prefer to use "git reset <CommitId>' rather than HEAD~1.

Patrick Diviacco March 30, 2016

2.) So if I want to revert to HEAD-2, I do need to call twice revert? Is there a simper way to revert (without using reset that is destructive command)?

Johannes Kilian
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 30, 2016

Yes you would need call revert twice.

I think "git revert" is the simplest way to revert - and it is IMHO the "easiest to reproduce" way (esp. for your fellow developers)...

Have a look here: http://stackoverflow.com/questions/1463340/revert-multiple-git-commits

Patrick Diviacco March 30, 2016

Thanks for the link. I've found in a comment to an answer this shortcut: git revert --no-commit D C B . I haven't tried yet, but it seems possible to revert multiple commits in one line, and then commit.

Johannes Kilian
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 30, 2016

Sounds good - but I personally would be scared about what happens on reverting multiple commits at once in case of having edited the same portions of code in different commits: Hopefully git reverts the changes back in "the correct order" ...

Seth
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 31, 2016

Probably reverts in the order specified, but check the documentation to confirm. You generally want to revert the most recent first.

Johannes Kilian
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 31, 2016

I Wonder what happens if I do incremental manual revert in this case, using oldest first (and most recent at last) ... Have to check this out as soon as I find some time

0 votes
Seth
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 30, 2016
  1. You can't do that. Partial solution: you can quickly see the most recent change to a particular line using "Blame".
  2. In the SourceTree UI, you can right click a commit and select "reverse" to undo changes in that commit. Like on the command line, this can only be done one commit at a time.

 

Patrick Diviacco March 30, 2016

I've actually found this: git revert --no-commit D C B . I haven't tried yet, but it seems possible to revert multiple commits in one line, and then commit.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events