Domanda

I am learning Git by reading the book "Pro Git", it said there are 3 states in Git they are 'modified', 'Staged' and 'Committed', I just can't understand what stage actually is and when it is used.

I searched on line and find this answer https://softwareengineering.stackexchange.com/questions/119782/what-stage-means-in-git-source-control, people said 'Staged' gives you better control when you want to partially commit the file.

My question is instead of staging the files for partial commit, can I just commit part of the file I want to and leave the rest of the file as 'modified'? Thus it seems that I don't need a 'Staged' state here.

Thanks.

È stato utile?

Soluzione

Yes. You can use git add -i means "interactive" and select the hunks of changes that should being added to stage and leave those which should not being added to stage. What has been staged can then be committed using git commit afterwards.

Altri suggerimenti

I would suggest that instead of reading a book, you should go for an interactive git tutorial. In this way you will learn by doing yourself :-)

Have a look at this http://pcottle.github.io/learnGitBranching/

In a nutshell, you run git status to see if anything has been modified and/or staged since your last commit so you can decide if you want to commit a new snapshot and what will be recorded in it.

http://gitref.org/basic/

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top