3 ms·
That's only true if you don't want to undo any changes. What's the easiest way to get back the previous version of function foo() in file bar.py if I already ma
by sorenjan 3y ago
That's only true if you don't want to undo any changes. 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?
Keeping a "bar copy(2) final working.py" file is not about having a nice looking timeline, it makes it very easy to get back to a working state. All you need is copy and paste, or keep the working function as a comment in bar.py. You can see your working code and know you're not messing with it when you're experimenting with bar.py. I'm not saying that's the best way of doing it, but it's a very common use case that's not usually addressed in git guides, where it's all about pushing commit after commit, maybe branching, maybe pushing to a remote with others, but rarely enough focus on undoing mistakes after some experimenting if you didn't branch first.
- dolni 3y ago> 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.
- sorenjan 3y agoI'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.