What is the version control tool 'Git' like?


I briefly summarized "What is the version control tool Git ?" For this time we focused on the concept and way of thinking of Git, for people like "I do not know exactly what Git is" or "I did not understand what I actually touched the code ..." I am writing an article.

Git
https://git-scm.com/

Version control means to "save files separately at some point" in short. If you save it in another file, you can start again from there. If you intuitively do this, it tends to be "manual file name versioning" as shown below. However, this "manual file name versioning" is often decided based on the idea of ​​naming, and it is a problem that it tends to become "I do not know which is the latest latest file" when looking at it later.


One solution to this is "Create a folder" working "in the project folder and update this contents."


In this policy, there is a version control method that copies the "working" folder when changing to "I want to save it here", and changes the folder name to a fixed format such as date and time.


And "Git" makes the above work easier and more wisely. "What saved the contents of a folder at a certain point in time" is called a "snapshot". Also, saving "snapshot" is called "commit".



I edited yesterday what I had committed last week, committed again, edited what I committed yesterday and commit again today ... and if I make a commit like this, I always committed before It is possible to return to the state of time. Git recalls the correct question, "The same file is saved many times and the capacity increases", but Git seems to be able to save only the files that need fine.



The commit is a random name according to a certain rule and can not be named by oneself. Since the commit name does not even include date and time information, it is becoming more difficult to identify "which is the latest commit". So, the one that named a specific commit is "branch".



The branch will move with a new commit. Therefore, if you look at the commit pointed to by the branch, you know which is the latest commit or one shot. In Git, the "master" branch is set by standard setting even if you do not have to be concerned about any branch, and if you do not change anything, you will be working on this master branch.



There is a "tag" in a function similar to a branch. Like a branch exists to name a specific commit, but unlike a branch it does not move even if there is a new commit, it always points to a commit at the time of setting.



"What branch is working" is called "HEAD". The figure below shows that in the book's writing, we newly set the "New chapter writing" branch to commit "1" which was already published, and the state of committed "2" and "3". "HEAD" shows the "New chapter writing" branch because I am working on the "New chapter writing" branch.



Here, it is said that you wanted to make a lithography before submitting the revised edition, so suppose that you corrected the spelling mistake first. When you switch HEAD to the "publishing" branch, Git will automatically replace the contents of the folder with that of the commit pointed to by the "publishing" branch. Uncommitted files disappear, so you need to commit them properly before switching branches.



We corrected spelling errors and created a new commit "4". In this commit "4" state I will publish heavy press.



Here, we will incorporate the new chapter that we wrote earlier to publish the revised edition. In this way, merging two branches is called "merge". If the same place is not edited in two branches, it is easy to merge, and even if the same place has been edited, Git will tell you the contention part, so just modify that part will merge I can do it. As you can see, using Git avoids the double effort of changing misspellings in two places, "file for lithography" and "file for revised version".



Following Git's review is as follows.

· It is "commit (commit)" to save the contents of the folders at a certain point in time

· "Branch" to manage the latest commit
In this article I stated that the branch will automatically move to a new commit, but in fact it is only when "I was working on a branch (= HEAD was pointing to a branch)" moved to a new commit To do. For example, if you are working with the "New chapter" branch after having two branches of "publication" and "new chapter" at the same commit "1", moving even if creating a new commit is " Chapter "branch, and the" Publish "branch never moves automatically.

· Use "tag" to name commit

· HEAD indicating which branch you are working with
The branch pointed to by HEAD may be displayed with an asterisk like "master *".

· Merging multiple commits is "merge"

After learning the above, it is recommended to check the operation by actually entering the command on the tutorial site etc.

in Software, Posted by log1d_ts