5 ms·
Say you want to find a commit that occurred around June three years ago, and look at what the repo looked like after that commit -- without checking out any fil
by mehrdadn 7y ago
Say you want to find a commit that occurred around June three years ago, and look at what the repo looked like after that commit -- without checking out any files. How do you currently do it?
For me, I just Right click -> TortoiseGit -> Show Log -> scroll -> Right-click -> Browse Repository.
How long does it take you? For me it takes < 10 seconds (I just timed myself).
- gdxhyrd 7y agogit log, copy paste hash, git checkout If you have a dirty wd, stash. But, to be honest, I almost never perform that action, and when I do I use the web browser.
- mehrdadn 7y ago> git log, copy paste hash, git checkout You remember the hash of your June commit 3 years ago?? > But, to be honest, I almost never perform that action, and when I do I use the web browser. Web browser... for a local repo? Or do you mean you don't have a solution if your repo isn't on GitHub or you don't have an internet connection handy? (You should also time yourself on your web interface by the way.)
- gdxhyrd 7y ago> You remember the hash of your June commit 3 years ago?? ...which is what the git log above is there for. > Web browser... for a local repo? Or do you mean you don't have a solution if your repo isn't on GitHub or you don't have an internet connection handy? Yeah, local repo. You know, git is not GitHub. :) > (You should also time yourself on your web interface by the way.) Just paste the hash commit in the HEAD selector or even in the URL.
- manigandham 7y ago> "when I do I use the web browser" So a graphical interface then? I'm sure you can see why using a GUI for other functions is just as useful.
- gumby 7y agogit log | grep -- find the hash of the one I want. or git log > file and look at it in an editor. no need to change the tools just for this unusual action. I understand that YMMV -- de gustibus non disputandum est -- but I have ever understood the appeal of GUI tools especially for something like git. I do use magit, but even then I do most manipulation with the command line interface
- mehrdadn 7y ago> git log | grep -- find the hash of the one I want. This misses the point of the problem -- the point is you don't know precisely what string to grep for. > or git log > file and look at it in an editor. no need to change the tools just for this unusual action. I mean, nobody said this 1 reason should be enough to make you switch tools? I was just giving an example. And no, it's not "unusual" just because you say so to try to dismiss the problem. I know I use Browse Repository as well as the GUI logs pretty frequently, and they're godsends compared to your solution. And lastly: this is what your solution actually looks like: 1. Dump the entire log output into a temporary file 2. Open that temp file in your editor 3. Look through the commit messages/dates/names 4. Realize that's not quite enough to narrow down your search to a single commit (maybe you want to see the diffs or file paths or something else?) 5. Try to figure out which flags you should to pass to git log to dump all the info you need 6. Call git log again, hopefully now it dumps all the info you need 7. Open the temp file again in your editor 8. Scroll through your file containing diffs/names/whatever extra info you dumped 9. Type 'git checkout COMMIT -- file/path' once you find something 10. (Hopefully,) before you press Enter, realize you're about to trash your current copy of the file, which had some other changes 11a. Run git stash, and now suddenly messing up your staging area that you'd carefully staged changes in, and also messing up the file metadata (e.g. Make will now rebuild everything...), OR 11b. Figure out how to run git checkout-index -a -f --prefix=/destination/path/ so that you check the file out into a different directory. 12. Once you have a copy of that file, look through it, maybe examine/pull out the code you wanted (or whatever) 13. Remove the temporary file you checked out. 14. Remove the temporary file in your editor. 15. git stash pop. And somehow you always do all the above without making a mistake, otherwise have fun reverting or recovering lost data. With a GUI log TortoiseGit's log, you literally: 1. Click on a commit with the date you're interested in 2. Select Browse Repository 3. Double-click each file you want to examine to see the diff 4. If it's not the file you want, press Escape and click again. Not only is the number of steps smaller, each one is also significantly faster, and less risky too. No need to mess with a single temporary file, fire up your editor manually, or risk losing anything. Anyway, again: this was just 1 example meant to get the idea across, hopefully with the aid of your imagination to extrapolate to other scenarios. But if you're going to trash this all with "this never comes up" I don't really have the energy or interest to keep bringing up examples or try to convince anyone; you should just keep using the CLI.
- tannakartikey 7y agoNot against GUI or anything but just curious about doing it from CLI: git log | grep 'June 2017' (and remember the first 5 characters of hash) And then `got checkout <hash>`
- mehrdadn 7y agoI think you missed the part that said "without checking out any files"?
- debaserab2 7y agoWhy would checking out files matter? What exactly do you think the GUI is doing underneath the hood?
- mehrdadn 7y agoBecause it messes with your work tree. See here for a longer response: https://news.ycombinator.com/item?id=21800524 https://news.ycombinator.com/item?id=21800524
- lllr_finger 7y agoProbably just GitHub (the browser UI). If you want to do it offline or from the command line, I understand why you might hesitate want to check out files, but stashing in git is extremely easy.