Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> What's the easiest way to get back the previous version of function foo() in file bar.py if I already made other commits to the same file, and want to keep those?

You are operating under the assumption that foo() changes in a vacuum. That is an invalid assumption for lots of software changes.

Commits are supposed to contain one logical change each. That logical change may or may not cross function boundaries (often it will).

Reverting a commit should revert the logical change. That is how you accomplish what you're after in git.



I've seen so many people do the "select function body, copy, toggle comment, paste copy of function, try out ideas on this new version" workflow. I've done it plenty too in Matlab and similar during various labs at school. I'm not talking about best practice during software engineering, I'm talking about having the confidence your code can easily get back to a known good state if you want to experiment, like beginners should do a lot of.

And plenty of times functions are self contained enough that you can change the function body without changing other code as well.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: