Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: [OT] What is best practice for 'git reset'? (updated)

by haukex (Archbishop)
on Apr 20, 2017 at 13:46 UTC ( [id://1188409]=note: print w/replies, xml ) Need Help??


in reply to What is best practice for 'git reset'?

Not a git expert, but a quick test seemed to show me that git reset --soft 2.12_002 will leave the changes from the newer versions in the index, I don't think that's what you want, because a commit afterwards would put those changes back into the repo.

If you want to begin your work with a commit that undoes all the changes since 2.12_002, the following seems to work, even directly on master.

git revert --no-commit 2.12_002.. git commit -m "Rewind to tag 2.12_002" # continue work here

Another approach might be to base the new branch on 2.12_002 and then later merge that branch back into master, clobbering all the changes in master at the same time auto-resolving all conflicting hunks by favoring the start-anew branch. (Update 2: Changed wording of the previous sentence after re-reading the git-merge docs. This is a significant difference because changes in the master branch that don't conflict will still be reflected into the merge result! Perhaps the "ours" instead of "recursive" merge strategy might be better for clobbering, untested. If in doubt, use the above solution instead!)

git checkout -b start-anew 2.12_002 # - make edits here - git checkout master git merge -s recursive -X theirs \ -m 'Merge branch "start-anew" (based on 2.12_002)' \ start-anew git branch -d start-anew git log --oneline --decorate --graph

Update: Here's how I generated the fake repo for testing:

git init echo -e "Hello, World\n---" >foo.txt git add foo.txt git commit -m 'Initial commit' for VER in 001 002 003 004 do VER="2.12_$VER" echo -e "Added in $VER\n---" >>foo.txt git commit -am "Edit for $VER" git tag $VER done

And similarly the fake edit:

echo -e "Added in 2.12_005\n---" >>foo.txt git commit -am "Edit for 2.12_005"

Update 2017-04-21: Just noticed this cross-posting to perl.module-authors. Also, it appears we're talking about File::Path version 2.12_004 (GitHub).

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1188409]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (3)
As of 2024-04-25 20:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found