What's the use of the staging area in Git?

前端 未结 5 1022
青春惊慌失措
青春惊慌失措 2021-02-01 14:54

What is the point of git add . or git add to add it to the staging area? Why not just git commit -m \"blabla\"?

5条回答
  •  甜味超标
    2021-02-01 15:43

    We want a staging area because we want to choose exactly what / when we make commits

    Microsoft Word has the approach that you have suggested. Any changes made in a document are all saved together. There is no staging area. You got no choice. Simple, but inflexible.

    But Git gives you more power. You can choose when and how the changes you make are recorded. Complex, but powerful. Fundamentally: Git users are programmers, we're smart and capable, and we want that flexibility.

    Example:

    Freddie written some masterful lyrics. How can he save them in four separate commits AFTER he has already written them out?

    Mama, just killed a man

    Put a gun against his head

    Pulled my trigger, now he's dead

    Mama, life had just begun

    The staging area makes it possible for him to do this. It's a workflow akin to software development.

提交回复
热议问题