Using git as a distributed file system
If you are already comfortable with a centralized workflow in your company or team, you can easily continue using that workflow with Git. Say John and Jessica both start working at the same time.
John finishes his change and pushes it to the server. Then Jessica tries to push her changes, but the server rejects them. This is also not limited to small teams. To contribute to that project, you create your own public clone of the project and push your changes to it. Then, you can send a request to the maintainer of the main project to pull in your changes.
The maintainer can then add your repository as a remote, test your changes locally, merge them into their branch, and push back to their repository. The process works as follows see Integration-manager workflow :. One of the main advantages of this approach is that you can continue to work, and the maintainer of the main repository can pull in your changes at any time. This is a variant of a multiple-repository workflow. All the lieutenants have one integration manager known as the benevolent dictator.
The benevolent dictator pushes from their directory to a reference repository from which all the collaborators need to pull. The process works like this see Benevolent dictator workflow :. Here we will be demoing with just plain text instead of actual code, since the main focus of this article is on Git and not on any specific programming language.
Committing is the process in which the code is added to the local repository. Before committing the code, it has to be in the staging area. The staging area is there to keep track of all the files which are to be committed. Any file which is not added to the staging area will not be committed.
This gives the developer control over which files need to be committed. If you want to add all the files inside your project folder to the staging area, use the following command:. Enter a relevant commit message to indicate what code changes were done in that particular commit.
Use git status to find out information regarding what files are modified and what files are there in the staging area — it shows other information as well, which we can ignore for now.
Now let us add demo. Up until now we have not created any branch in Git. By default, Git commits go into the master branch. A branch is nothing but a pointer to the latest commit in the Git repository. Multiple branches are needed to support multiple parallel developments.
Refer the image below to see how branches work. Initially, commit 1 and commit 2 were done in the master branch. At the same time, a different commit 3 and commit 4 are added to the master branch.
Here we can see that after Commit 2, two parallel developments are being done in 2 separate branches. The Test Branch and the Master Branch have diverged here and have different code — the code from Test Branch can be merged with the Master branch using git merge. This will be covered later. We are still in the context of the master branch. In order to switch to the test branch. This commit was done in the Test Branch, and now Test Branch is ahead of Master Branch by 1 commit — as the test branch also includes the 2 commits from the master branch.
Currently, Test Branch is ahead of the Master by 1 commit. This is where git merge is very useful. After running these 2 commands, the merge should be successful.
In this example, there are no conflicts. But in real projects, there will be conflicts when a merge is being done. This stores the actual name of the file, the file server IP and Port it is stored on and whether the file server is holds the primary copy or not. If a client wishes to write to a file the directory service sends the request to fileserver A, the holder of the primary copy. If the client wishes to read from a file the directory service sends the request to fileserver B or fileserver C, these hold replicated versions of the files on fileserver A.
If client 1 wishes to write to a file it requests to lock the file for writing. Client 1 can only write to a file when it receives the lock, it can read from a file whenever it wants. If client 2 wants to write to a file and the file is locked for writing then client 2 must wait until client 1 has unlocked it.
Client 2 who is requesting the write will keep polling to check for the unlocked file. I have included a 10 second timeout for polling which is a short period of time for simulation purposes.
If client 1 is writing to a file and client 2, client 3 and client 4 request to write to the file in this order, client 2 will be the first client to retrieve the lock on the file. When client 2 finishes, client 3 will get the lock, and then client 4, etc. This is fair locking and unlocking. It works as a FIFO queue. If a client requests to write to a file it goes to the fileserver with the primary copy. The write also goes to the client's cache.
The version number of the file is stored on the client side and on the fileserver side. If the client next wishes to read the file, it compares the version number on the fileserver side and the version number on its side. If they match then the client reads from its cache. If they do not match the client reads from the fileserver and updates its record of the version number for the file.
0コメント