Imagine a box. You can put stuff into the box. You can take stuff out of the box. This box is the staging area of Git. You can craft commits here. ...
For further actions, you may consider blocking this person and/or reporting abuse
Clear explanation! Any five-year old could now get how git works! Also had a laugh in the process
I am just a bit confused about "git revert" and the anti-box. Could you please explain more? Does it mean we have the ability to revert the last commit? After typing "git revert" isn't it reverted automatically?
P.S.: Would love to see a second post with the box analogy explaining more about git!
A
git revert
will create another commit that is an exact mirror opposite of the commit you are reverting.In my example, a sealed box is a commit. If you have a commit where you add 2 lines and remove one. The reverted commit will remove 2 lines and add one, effectively nullifying your original change.
This is why I was making the juxtaposition to anti-matter where a commit and a reverted commit combined would be the same as no commit.
Does that make sense?
Yes, very clear!
But do we have to commit this new anti-box? Or is it pushed automatically?
Whenever you perform a
git revert
the commit is created automagically for you. You can see it if you perform agit log
or use a Git GUI like Sourcetree.IF you want to make your revert public, you would do a
git push
and your local repo would be synced with the remote repo, assuming no conflicts with the public repo are present.Thank you!
Awesome explanation! I'm already quite comfortable with git after a lot of reading and research, but this is the explanation I would've wanted back when I started.
I'd even suggest a follow up article about why the staging area is such a cool idea, using the box analogy. (Other version control systems without a staging area can only create labeled boxes by dumping the entire contents of your desk into the box all at once... git allows you control over what goes into each labeled box...etc)
Great idea!😁
How do I open one of the many sealed boxes find some old code and bring it back to life?
Let's say, I deleted a bunch of files in favour of one that does what all these other files were doing. That was 3 or commits ago. Now, I just remembered that one of the files would be useful to me.
Git checkout
Ok, I get that this opens the box. Now my HEAD is in the box, but how do I recover the one file?
Well, depends on what you mean by recover. If you checked out the commit, you'll see the version of the file you want. If there's a lot of changes you can make a copy and then paste it over the latest commit. If there's a few, you can revert lines or hunks selectively.
Two remarks
Same as --hard except you preserve ignored files.
(Pretty much always better)
So helpful! Really good for beginners :)
How could you resolve conflict?
Stare at the box. You feel compelled to argue with it. It wins. Every time.
Informative peace of information!