Still having a hard time getting my head wrapped around the concept of staging as it applies to Git.
Can any analogies be made with SVN? What is the primary purpose of having a stage level in Git?
Still having a hard time getting my head wrapped around the concept of staging as it applies to Git.
Can any analogies be made with SVN? What is the primary purpose of having a stage level in Git?
Similarities:
Files that should be part of the repository must be added in order to being tracked. Both tools use the add
command to accomplish this. Adding files means to prepare a commit.
Differences:
Git allows some further kind of detail when adding files. You can decide to add a whole file or distinct lines of code. Adding files to the index or stage allows more flexibility. SVN automatically commits all changes on a file that has already been added to the repository. Git leaves the decision of what changes to associate with each commit operation to the user. In other words: the next commit in Git only contains those changes (lines or files) that have been staged, regardless of the tracking status of the files. SVN automatically includes all changes on tracked files.
Additional information:
Try to read some posts describing Git workflows such as the one from Oliver Steele. But be aware that there is not one way to use Git - there are many. If you want, you can use Git as if you were working with SVN.
Do not expect to understand the philosophy of Git in a short period of time. It took me a year to get into it and I still learn new ways to use it. I think it is even harder if you grew up with SVN mindset. There are tons of materials out there: articles, videos, ... - take your time and try some of them. Here is a selection from the list I collected.
git pull
--> There is a command git pull --rebase
which avoids automatically created merge commits. –
Longoria git add
puts files onto the stage aka. adds them to the index. –
Longoria git stage
to my knowledge. –
Longoria The main advantage of the staging area is that you can easily commit only part of the changes in a given file. (Using git add -p
for instance.) As far as I know, the only way to do a "partial" commit in SVN is on a per-file level, or by manually backing up a file and then temporarily reverting the changes you don't want to commit.
This is great if (like me) you're not a highly organised developer and want to be able to sort out changes into "neat" commits after the fact. This follows Git's general attitude of preferring to give you flexibility over enforcing strictness. If you don't need it, you can always just not use it, and use git commit -a ...
.
There are no analogies to be made with SVN because SVN is not Git and does not have such a concept.
Similarities:
Files that should be part of the repository must be added in order to being tracked. Both tools use the add
command to accomplish this. Adding files means to prepare a commit.
Differences:
Git allows some further kind of detail when adding files. You can decide to add a whole file or distinct lines of code. Adding files to the index or stage allows more flexibility. SVN automatically commits all changes on a file that has already been added to the repository. Git leaves the decision of what changes to associate with each commit operation to the user. In other words: the next commit in Git only contains those changes (lines or files) that have been staged, regardless of the tracking status of the files. SVN automatically includes all changes on tracked files.
Additional information:
Try to read some posts describing Git workflows such as the one from Oliver Steele. But be aware that there is not one way to use Git - there are many. If you want, you can use Git as if you were working with SVN.
Do not expect to understand the philosophy of Git in a short period of time. It took me a year to get into it and I still learn new ways to use it. I think it is even harder if you grew up with SVN mindset. There are tons of materials out there: articles, videos, ... - take your time and try some of them. Here is a selection from the list I collected.
git pull
--> There is a command git pull --rebase
which avoids automatically created merge commits. –
Longoria git add
puts files onto the stage aka. adds them to the index. –
Longoria git stage
to my knowledge. –
Longoria Here are some of the scenarios that show the usefulness of staging:
You work on a particular piece and have made quite a few changes across your project. You don't want to commit them yet before testing out the full thing. But these changes can often be independent enough to make multiple logical commits than a single big one. This is when you stage selective parts and make multiple commits.
Staging has been especially helpful while debugging. You can sprinkle around the log statements to track the source of the bug. Then you make the fix, and test again using those log statements. But then, you want to commit the fix before making any change in the code to delete those log statements.
Another scenario where it has proved to be helpful is when you are in the middle of doing something, and find something unrelated, like a typo error, that you want to fix and get it out of the way quickly.
There are several other such scenarios, and probably you wouldn't be able to work with anything that lacks this concept, once you get a hang of it :).
PS: I have not used SVN at all, so can not make the comparisons between the two.
git commit <specific files>
. Of course this goes through the staging area, but only briefly on its way straight to the commit. –
Agonized © 2022 - 2024 — McMap. All rights reserved.