git 控制版本
So who am I?
那我是谁
My name is Anna and I teach Git (version control) both on Udemy and on my own platform www.techjourneywithanna.com!
我叫Anna,我在Udemy和我自己的平台www.techjourneywithanna.com上教Git(版本控制) !
And here are some tips I have for people learning Git.
这是我为学习Git的人们提供的一些技巧。
1.建立关于Git工作方式的思维模型 (1. Build a mental model of how Git works)
One of the most important things to do when learning Git is to build an accurate mental model of how it works.
学习Git时要做的最重要的事情之一就是建立准确的心智模型以了解其工作原理。
I say accurate because a lot of times when we first learn Git we adopt an inaccurate understanding of it.
我说的准确,因为很多时候,我们首先要学会的Git,我们采取的是不准确的理解。
Let me explain with an example.
让我举例说明。
A lot of fresh Git learners at some point start learning about branches. And from the name and the numerous colourful diagrams online it is easy to understand that branches in Git are like tree branches.
某些时候,许多新鲜的Git学习者开始学习分支。 从名称和在线上众多的彩色图表中,很容易理解Git中的分支就像树枝。
But, this is not the case!
但这种情况并非如此!
Branches in Git are simply pointers to commits.
Git中的分支只是指向提交的指针 。
To see this explicitly try this exercise.
要明确看到这一点,请尝试此练习。
Step 1: Go to any local repository on your computer
步骤1:转到计算机上的任何本地存储库
Step 2: Show all the hidden files so that you can see your .git folder (this is the folder that manages your repository). On a mac you have to hold down Cmd + Shift + . (dot). On a windows computer you will have to go into your settings to show hidden files. Then, look at the contents of the .git folder.
步骤2:显示所有隐藏文件,以便您可以看到.git文件夹 (这是管理您的存储库的文件夹)。 在Mac上,您必须按住Cmd + Shift +。 (点)。 在Windows计算机上,您必须进入设置才能显示隐藏文件。 然后,查看.git文件夹的内容。
Step 3: Inside the .git folder look at the contents of a folder called ‘refs’. And then look at the contents of a folder called ‘heads’. Here you should have one file for each branch in your repository.
步骤3:在.git文件夹中,查看名为“ refs”的文件夹的内容。 然后查看名为“ heads”的文件夹的内容。 在这里,存储库中的每个分支都应该有一个文件。
Step 4: Click into one of the files that represents a branch in your repository.
步骤4:单击进入代表存储库中分支的文件之一。
What do you see?
你看到了什么?
A commit hash!
提交哈希!
Because like we said, branches are simply pointers to commits. And that is why each branch file simply stores the commit hash that that branch is pointing to.
因为就像我们说的那样, 分支只是指向提交的指针。 这就是每个分支文件仅存储该分支指向的提交哈希的原因。
So, building the right mental model of how the Git machine functions is essential to working with it smoothly. And that was my main focus when I was designing my course.
因此,建立正确的Git机器功能思维模型对于顺利使用它至关重要。 这是我设计课程时的主要重点。
2.掌握基础知识 (2. Master the Basics)
Most of us when we first learned Git was taught the Git beginners mantra:
当我们初次学习Git时,我们大多数人都被教导Git初学者的口头禅:
🎶git add git commit git push git add git commit git push 🎶
🎶添加git commit git push git添加git commit git push🎶
But did we really understand in depth what was happening?
但是我们真的深入了解发生了什么吗?
Relearning Git was a very humbling experience for me because I had to go back to basics multiple times.
对我而言,重新学习Git是一次非常卑鄙的经历,因为我不得不多次回到基础知识上。
I was often embarrassed when I had to admit to myself that I didn’t REALLY know or understand some things (even after coding for months).
当我不得不承认自己并不真正了解或理解某些东西时(甚至在编码几个月后),我常常感到尴尬。
BUT! The minute I gave myself permission to be a complete beginner again and was humble enough to try to learn something from a blank canvas, amazing things happened! (And often I discovered I wasn’t the only one that had misunderstood something or didn’t really understand it.)
但! 当我允许自己再次成为一个完整的初学者的那一刻,我谦虚地尝试从一块空白的画布上学习一些东西时,发生了惊人的事情! (而且我常常发现我不是唯一一个被误解或真正不理解的人。)
For example, many of us when we first learn Git think that commits store the differences between one version of our project and another.
例如,当我们初学Git时,我们中的许多人都认为提交会存储项目的一个版本与另一个版本之间的差异。
But that is not the case. This is a false mental model to have.
但事实并非如此。 这是一个错误的心理模型。
Commits are like standalone versions of your project (or snapshots as they are often referred to).
提交就像项目的独立版本(或快照,通常称为快照)一样。
Each commit basically stores within it every single file that was a part of that version of your project.
每次提交基本上都在其中存储了项目版本中每个文件。
That is why when you check out a commit you are just looking at a different version of your project.
这就是为什么当您签出提交时,您只是在查看项目的不同版本。
3.与Git一起玩并自己进行测试 (3. Play around with Git and test things out yourself)
One of the best ways to get comfortable with Git and to really make sure you understand it is to play around with it. And test out whether how you think things work is how they really work.
熟悉Git并真正确保您了解它的最佳方法之一就是尝试使用它。 并测试一下您认为事情如何运作才是真正的运作方式。
Let me share a story. I had come across this very common diagram online:
让我分享一个故事。 我在网上遇到了这个非常常见的图表:
But then when I started tinkering around with Git I realized that this diagram was a bit misleading.
但是,当我开始修改Git时,我意识到此图有点误导。
For example, you may know (or now you will learn) that another term for the staging area in Git is ‘index’. They are the same thing.
例如,您可能知道(或现在您将学习)Git过渡区域的另一个术语是“索引”。 他们是一样的东西。
If you look inside the .git directory of any of your repositories (you can use the same one as you did in the first exercise) you will find a file called index.
如果您查看任何存储库的.git目录(可以使用与第一个练习相同的库),则会找到一个名为index的文件。
This is your staging area (no need to look inside the file, it’s gibberish and beyond the scope of this article).
这是您的暂存区域(无需查看文件内部,这很乱,超出了本文的范围)。
So actually the staging area is inside the .git directory. So it would be more accurate to make an annotation to the above diagram.
因此,暂存区实际上位于.git目录中。 因此,对上面的图进行注释会更加准确。
In order to build a more clear mental model of what was happening, I even went so far as to draw out a new diagram that would help me understand things better. And this is the diagram I used in my course in order to explain all the different parts of Git!
为了建立更清晰的事件发生心理模型,我什至甚至画出了一个新的图表来帮助我更好地理解事物。 这是我在课程中用来解释Git所有不同部分的图表!
If you want an explanation of the different part of this diagram check out this video and this video.
So, take some time to try things out in Git and test out what you think you know this will help you gain a lot more Git confidence.
因此,花一些时间在Git中进行尝试,并测试一下您认为自己知道的知识,这将帮助您获得更多的Git信心。
4.花时间从你的斗争中学习 (4. Take the time to learn from your struggles)
You are at work and you come across a Git problem. Or you’re working alone at home and you find yourself in a sticky Git situation.
您正在工作,并且遇到了Git问题。 或者您独自在家工作,发现自己处于粘性Git状态。
So you call out for help from those more experienced masters of Git (senior developers etc.).
因此,您需要向经验丰富的Git大师(高级开发人员等)寻求帮助。
They come.
他们来。
They save you.
他们救了你。
And you are back in safe waters.
您又回到了安全的水域。
This was basically me my first few months working as a developer. And what I wish I had done more often is asked my saviors to explain to me in depth what I had not understood. Or to have taken the time to study the situation independently. It would have made for a much smoother and more succinct Git learning journey!
这基本上是我作为开发人员工作的头几个月。 我希望我做得更多的是我的救世主,向我深入解释我不了解的事情。 还是花时间独立研究情况。 它将使Git的学习过程更加顺畅和简洁!
That was it! I hope the above four tips help you on your Git learning journey!
就是这样! 希望以上四个技巧对您的Git学习之旅有所帮助!
If you are looking for an online course that teaches Git in a simple and accessible way then feel free to check my course out on Udemy or on my own platform www.techjourneywithanna.com!
如果您正在寻找一种以简单易用的方式教授Git的在线课程 ,请随时在Udemy或我自己的平台www.techjourneywithanna.com上查看我的课程!
You can also :
你也可以 :
Check out my YouTube channel on which I have the first 8 lessons of my course! 📹
看看我的YouTube频道上,我有前8个教训我的课程 ! 📹
Follow me on instagram @techjourney_with_anna 😊
加入我的邮件列表 ✉️
Follow me on Eventbrite 🗓
在Eventbrite上关注我
Connect with me on LinkedIn 💼
在LinkedIn上与我联系
Or just shoot me an email: annaskoulikari@gmail.com
或只是给我发电子邮件: annaskoulikari@gmail.com
Bonus: For any French speakers 🇫🇷 out there, my course is also available in French!
奖励:对于所有在那里讲法语的人, 我的课程也提供法语 !
git 控制版本