GitKraken detailed graphic tutorial

foreword

The reason for writing this article is that the products and art students in the group began to participate in the git workflow, but I couldn’t find a more detailed tutorial on the Internet, so I simply wrote a [doge]. The content of the article is relatively basic, introducing some basic concepts and basic operations in Git, suitable for people with zero foundation as an introductory guide.

Some common concepts of Git

1. Warehouse (repository/repo): The warehouse of code and resources. Git is divided into local warehouse and remote warehouse. Git will synchronize the contents of the remote warehouse to the local when starting and actively pulling. The remote warehouse is hosted on the server, there will only be one copy, and it will always be kept up to date. There can be multiple copies of the local warehouse, each person's local warehouse does not affect each other, and can be modified offline.

2. Clone: ​​When the remote warehouse has been built and there is no local warehouse. The remote warehouse needs to be cloned locally. When the clone is just completed, the local warehouse is exactly the same as the remote warehouse.

3. Branch (Branch): In a warehouse, an initial master branch will be generated when the commit is initialized. Other new branches can then be created on top of this master branch. When you need to do some operations and don't want to affect others, you can create a branch separately, develop the function on the branch, and finally merge (Merge) it into the trunk.

There is also a difference between local and remote branches, and the remote branch records the content of the branch in the remote warehouse. The local branch is to save the modified content of your local warehouse. If there is a remote branch but no corresponding local branch, you can check out (Checkout) to get a local branch.

On the left side of GitKraken, you can see all local (Local) and remote (Remote) branches. At the same time, you can also see the remote and local branches on the main panel in the middle. The remote branch is displayed as a circular icon, and the local branch is displayed as a small computer icon.

GitKraken interface introduction

Main interface

The main interface of GitKraken is as follows, with the current project displayed at the top. In the middle is the graphical Git submission record, you can see the submission status of the current project, and on the left is the local/remote branch and storage areas. The right side is the file modification area

Git file modification area

In the file modification area, when a file changes, the following prompt will appear

Click View change to switch to the following interface to process the current modification

In the file modification area on the right, you can see several different file states

Yellow means that the file has been modified (local and remote are different)

Red means that the file has been deleted (remote exists, local does not exist)

Green means that the file is a new file (local existence, remote does not exist)

It should be noted here that if there is no modification locally, the modification area will not be displayed

When left-clicking on the file in the modification area on the right, it will enter the modification preview interface. You can see the specific file modification status. There are thumbnails of file modification status in the sidebar, which can be dragged to find the corresponding modification location. On the left is the actual modification. After viewing, you can choose to temporarily save the file or close the preview

GitKranken basic operations

Discard modification ( Discard )

If you do not want the local modification, you can choose to discard the local modification, the specific operation is as follows

(1) Discard a single modification

In the modification area, if you want a modification, you can right-click the file and select Discard changes

After that, a confirmation pop-up window will appear at the top, click the Discard Unstaged changes button to restore to the state before modification

Both modified and deleted files can be Discarded. If it is a newly added file, if you want to restore it, you need to right-click Delete file.

(2) Discard the modifications in the folder

If you want to discard all the modifications in a file, you need to switch the modification area to Tree mode first, so that the files in the modification area will appear in a tree structure

Then right-click to select the folder to be discarded, click Discard all changes in folder

Then click Reset Files in the top pop-up window

(3) Discard all modifications

If you want to ignore all modifications, you can click the trash can in the upper left corner

Then a pop-up window will appear at the top, click Reset All to clear the entire modification area

Storage ( Stash )

Click Stash at the top to store all the modifications in the current modification area.

The corresponding modification will be placed in a small drawer in the picture below. And the Stash will be automatically named according to the branch. The message stored on develop will be automatically named WIP on develop

If you want to modify the name of Stash, you can click this small drawer, click the Stash Message box on the right, and modify this Message

In the future, if you want to restore the modification in this Stash, you can right-click the line where the small drawer is located, and then select Pop Stash

Commit changes ( Commit )

Git can complete offline development work, and all submissions can be submitted (Commit) to the local branch first, without affecting the remote branch at this time.

The specific operation is to move the mouse to the modified file and click on the StageFile on the right to temporarily store (Stage) the file

You can see that the file has been moved to the Staged Files area below

If you want to temporarily store all files, you can click Stage all changes in the upper right corner

Temporary storage by folder is to right-click the folder and select Stage folder

After all the files that need to be temporarily stored are placed in the temporary storage area, fill in the modification log in the Commit Message, and click Commit changes to submit the modification to the local warehouse

After submitting the modification, you can see that there will be a submission record corresponding to the log on the main interface.

Pull _

When someone else submits some changes to the remote branch, it is necessary to synchronize other people's modifications to the local through the Pull operation. The operation of Pull is very simple, just click the Pull button at the top

Before making a pull, there are two types of status of local branches:

The first type is the simplest, where both local and remote are on the same line. Indicates that no files have been committed locally, but others have pushed some changes to the remote branch

At this time, after the Pull operation is performed, the identifiers of the remote and local branches are in the same place, indicating that the Pull is successful, and the local and remote branches are exactly the same.

The second type of situation is that the modification is made locally and after Commit, it is not pushed to the remote end.

At this time, the local and remote branches are on two lines and the local and remote branches are not merged together. When the modification time of the remote branch is after the local Commit, the remote branch is displayed above the local branch

Otherwise the remote branch is displayed below the local branch

Just click Pull to pull. After the pull is completed, you can see that although the remote code and the local are still on two lines, the remote branch has converged to the local branch, which means that the pull is successful.

Push _

When it is necessary to push the modification of the local branch to the remote branch, a Push operation is required. It should be noted that the Pull operation needs to be performed before the Push, and the Push can only be performed after the contents of the remote branch are synchronized to the local branch.

The Push operation is also very simple, just click Push on the top

After the Push is successful, you can see that the small dot and the small computer are in the same row at this time. It means that the Push is successful, and the local and remote branches are exactly the same.

Create Branch ( Create Branch )

Right-click where you want to create a branch and select Create branch here

After that, a pop-up window of enter branch name will appear on the left side. After entering the branch name, click Enter to create a branch

The branch entered here is called testBranch. You can see that there will be a small computer icon after creation, representing the local branch

Check out branch ( Checkout )

When you want to switch from one branch to another, you can switch through Checkout. The specific operation is to right-click the branch to be switched and select "Checkout branch name". (This operation can also be simplified to directly double-click the branch)

When you switch to this branch, you can see a " tick " icon on the left side of the branch.

Checkout can choose to switch to a local branch or a remote branch. If there is no local branch, you can directly double-click the dot where the remote branch is located.

A local branch is automatically generated.

If the local branch already exists, and the local branch and the remote branch are not in the same location, select Checkout the remote branch, and the following prompt will appear. If you choose Reset Local Here, it is equivalent to resetting all local branches and synchronizing to the location where the remote branch is located. (Special attention, this operation will discard all local Commits that have not been pushed , so do not perform this operation lightly) If you do not want to reset the local branch, you can select Cancel to cancel. In most cases, if there is a local branch, checkout the local branch first, and then pull to update to the latest.

Merge branches ( Merge )

Merge operations can be performed between different branches. For example, after you have made some changes on your branch and want to synchronize the changes to the trunk, you can perform Merge operations. At the same time, you can also synchronize the modification of the trunk to your own branch.

The specific operation is to switch to the target branch first, then right-click the source branch to be merged, and select "Merge source branch into target branch". In this way, the content of the source branch can be merged on the target branch.

After the Merge is successful, a merged log will be automatically generated. And the line represented by the source branch also converges to the target branch

Adopting a commit (Cherry Pick Commit)

Sometimes you make multiple modifications on a certain branch, such as "adding pictures" (A), "modifying picture parameters" (B), and "modifying code" (C). At this time, if you want to apply A modification on another target branch, but you don’t want other modifications to be merged into the target branch, you can implement this operation through Cherry pick commit.

The specific steps are, right click on the submission to be adopted, and then select Cherry pick commit

After the operation is complete, you can see a log that is the same as the adopted commit on the target branch

Revert Commit

If a modification that has been submitted and you want to restore it to the state before the submission, you can use the Revert Commit operation. Just right-click on the commit that needs to be restored and select Revert commit

After the operation is completed, a Revert log will be automatically generated

Resolve Conflict

Dealing with conflicts is the most troublesome part of the git workflow. The general reason is that two branches have modified a file at the same time. Here is a simple example to simulate such a situation. Both BranchA and BranchB have a file TestScript.cs, which declares a variable a, and the value of a is 0 at the beginning.

XML
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class TestScript : MonoBehaviour
{
    int a = 0;
}

Then change the value of a to 100 in BranchA and 50 in BranchB. Then try to merge BranchB to BranchA.

You can see that a Merge Failed prompt will pop up in the lower left corner

And there will also be a yellow prompt at the top, and the Conflicted Files in the file modification area will show which file is in conflict.

Click the file in the conflict area to enter the interface for dealing with conflicts. You can see that the conflict interface has three areas

The upper left corner is the content of BranchA

The upper right corner is the content of BranchB

The bottom is the content of the output area

At this time, if you want to adopt the submission of BranchA, you can click the check box on the left side of the row where the conflict occurs

You can see that the content of the output area below also becomes the same modification as BranchA

At this point the conflict is resolved. You can click the Save button in the upper right corner to exit the conflict handling interface.

At this point, you can see that TestScript.cs has moved from the conflict area to the temporary storage area below. And the Commit Message is automatically filled in. If you decide to use this conflict handling, you can click Commit and Merge on the left to complete the entire process of merging conflicts

The Merge successful Commit message will also appear on the main interface

In the actual operation process, there will be multiple conflicts in a single file. You can see the output area Output, and conflict n of m will be displayed. n means that the current view is the nth conflict, and m means how many conflicts there are in total. You can click the arrows on the right to switch between different conflicts.

Sometimes there are too many conflicts in a single file. Or because of modifying prefab or scene, I don't know how to deal with conflicts one by one. At this time, you can directly click the two check boxes at the top to choose which branch file to use directly. For example, click the check box of A on the left, which means to directly adopt the file on BranchA and completely ignore the modification on BranchB. Later, you can wait for the conflict to be resolved and then manually add the modification on BranchB back.

When dealing with which file to directly use when dealing with conflicts, it is recommended that you choose according to the following principles

(1) Prioritize the use of files modified by others

(2) Prioritize the use of remote branch files

(3) Prioritize the use of files with more revisions

There is another simple and rude way to deal with conflicts, which is to select Mark all resolved in Conflicted Files

This way GitKranken will mark all conflicts as resolved. But in fact the content of the file is not correct. For example, in the previous example of modifying the value of a, the output content of selecting Mark all resolved is as shown in the figure below. At the same time, fill in the contents of the two branches, and there are

The prompt "<<< Head === >>> branchA" automatically output by Git still needs to be solved manually in the end.

GitKranken operation process

1. Clear the modification area

Before pulling or switching branches, you need to clear the modification area first.

There are several ways to clear:

(1) Discard modification (Discard)

(2) Storage (Stash)

(3) Submit the modification (Commit)

For specific operations, please refer to the corresponding basic operations in the previous chapter

2. Determine the branch

After clearing the modification area, you need to determine which branch to operate on. Then you need to switch to the corresponding branch. You can first check whether the branch exists locally. (Local column on the left), if it exists. Double-click the branch directly to switch to the branch. If the local warehouse of the branch does not exist, you can directly double-click the remote branch, so that you can checkout a corresponding branch locally and complete the switch.

3. Synchronize remote branches

After switching to the corresponding branch, a Pull operation is required to synchronize the modification of the remote warehouse to the local. Click the Pull button to complete the Pull operation

4. Modify locally

When making local modifications, you can freely create local branches, store them, or submit them locally.

After clicking the storage button, you can see a small drawer icon appear on the top, and all local modifications are temporarily saved in this storage

Then pull the latest branch again to verify the final effect.

If you find that you still need to modify it, you can directly modify it on the latest branch. You can also restore the stored content according to the situation, right-click the small drawer that was just stored, select Pop Stash, and restore the modification.

FAQ

1. The file is used by other programs

When performing file operations (such as Stash, Discard, etc.), the following pop-up window may appear, resulting in inability to operate. The reason is that some files are used by other programs, such as player, picture viewer, etc. At this time, you need to close the program that occupies the file, and the operation can proceed smoothly. (If you really can't find which program it is, you can restart the computer)

2. Switch branch failed Checkout Failed

When performing branch switching, sometimes the following error will be reported because the modification area is not cleared. Clear the modification area and then switch branches.

It’s not easy to create. If you think this article is helpful to you, you can move your little hands and give it a thumbs up. ღ( ´・ᴗ・` ) love

Guess you like

Origin blog.csdn.net/shaobing32/article/details/132314377