Basic Git commands and uses
n5321 | 2024年11月29日 00:39
Git is a popular version control system that allows developers to manage changes to their codebase, collaborate with others, and maintain a history of their work.
Git的价值就在这个台词里面了。
- manage changes,对变化的挂历,track, monitoring changes to your code over time. Git makes it simple to track changes to your codebase and collaborate on projects with others.
- collaborate with others.
- maitain a histroy!
It enables us to track changes in our code and collaborate with others by working independently on a different part of a codebase.
Git has three storages locally: a Working directory, Staging Area, and a Local repository.
Working Directory
This is where you work and your files live ("untracked"). All file changes here will be marked; if not saved to GIT, you will lose them. The reason is that GIT is not aware of those files.
Staging Area
When you save your changes with git add, GIT will start tracking and saving your changes with files. These changes are stored in the .git directory. Then, files are moved from Working Directory to Staging Area. Still, if you change these files, GIT will not know about them; you need to tell GIT to notice those changes.
Local Repository
It is the area where everything is saved (commits) in the .git directory. So, when you want to move your files from Staging Area to Local Repository, you can use the git commit command. After this, your Staging area will be empty. If you want to see what is in the Local repository, try git log.
But you don't just want to learn commands, you want to understand what you're using?
这也是一个很漂亮的台词。
Tech Talk: Linus Torvalds on git
youtube上的一个视频,介绍Git的背景,看了一半,很厉害的。!
[Introduction by the Host]
MALE SPEAKER:
Thank you for coming, everybody. Some of you have probably already heard of Linus Torvalds. For those who haven’t, you’re the people with Macintoshes on your laps.
Linus is a guy who delights in being cruel to people. His latest cruel act is to create a revision control system expressly designed to make you feel less intelligent than you thought you were.
Thank you for coming down today, Linus. I've been getting emails for the past few days from people saying, "Where's Linus? Why hasn’t he measured my tree? Doesn't he love me anymore?" And then he walked into my office this afternoon.
"What are you doing here?" But thank you for taking the time off. So Linus is here today to explain to us why on Earth he would write a software tool which only he is smart enough to know how to use.
Thanks, Linus.
[Linus Torvalds Begins]
LINUS TORVALDS:
So I have a few words of warning. I don’t actually do much public speaking, partly because I don’t like speaking, and partly because over the years, people want me to talk about nebulous visions for the next century regarding Linux.
I’m a tech geek, so I actually prefer talking about technology. That’s why I am not talking about the kernel today—it’s just too big to cram into a one-hour talk. (Although apparently Andrew did that two days ago.)
Instead, I’m talking about Git, the source control management system we use for the kernel.
[On Presentation Style]
I’m really, really, really bad at making slides. If we actually follow these slides, you’ll be bored out of your mind, and the talk won’t be very good anyway.
I enjoy getting questions during talks. If that means we veer off on a tangent, that’s fine—you’ll be happier, I’ll be happier, and the talk will probably be more interesting.
So don’t feel shy as far as I’m concerned. If your manager might shoot you for asking a question, that’s your problem.
[Credits and Acknowledgments]
First, I’d like to credit CVS (in a very negative way). Many of Git’s design choices stemmed from a “What would CVS never do?” kind of approach.
I’ve never used CVS for the kernel. For the first 10 years of kernel maintenance, we literally used tarballs and patches, which were superior to CVS in every way.
That said, I used CVS for seven years at a commercial company, and I hated it with a passion.
If there are any Subversion (SVN) users in the audience, you might want to leave now. Subversion’s slogan used to be “CVS done right,” and as far as I’m concerned, there’s no way to “do CVS right.”
On the positive side, I’d like to credit BitKeeper. It was the first source control system I felt was worth using, and it taught me the value of such systems. While Git is technically very different from BitKeeper, many of its workflows were inspired by BitKeeper.
[Git’s Evolution]
I started working on Git over two years ago. While I made the initial coding and design decisions, Git has been maintained for the last year and a half by Junio Hamano, a much more pleasant person. Junio made Git approachable for mere mortals.
The early versions of Git required significant brainpower to use, but it has since become much easier. Of course, my approach to life is to get everyone else to do as much work as possible while I sip pina coladas.
[Why Distribution Matters]
The key feature of Git is its distributed nature. Distribution is critical for several reasons:
- Offline Work: With a distributed system, you can work completely offline—on a plane, for instance—without needing a network connection.
- Branching and Merging: Distributed systems inherently encourage more branching. In Git, branches are lightweight, and merging is straightforward.
- Trust and Reliability: Distributed systems provide better data integrity and security. Even if your machine crashes, your repository is mirrored elsewhere.
In contrast, centralized systems like CVS or Subversion create significant bottlenecks. They require commit access and lead to endless politics over who gets access to the central repository.
[Git’s Design Philosophy]
- Performance: Git is fast—really fast. For example, it can diff the entire Linux kernel in under a second.
- Data Integrity: Git uses SHA-1 hashes to ensure that data is secure and unchanged. If any corruption occurs, Git will detect it immediately.
- Content-Based Tracking: Git tracks content, not files. This approach allows it to handle operations like branching and merging far better than systems that focus on individual files.
[Conclusion]
Git enables a completely different development model, emphasizing flexibility, speed, and trust. Whether you’re working on an open-source project or in a corporate environment, Git’s distributed nature eliminates many of the problems inherent in centralized systems.