This article has participated in the “Digitalstar Project” and won a creative gift package to challenge the creative incentive money.
A series of
Because of the length problem, one article is too long to write, so divided into several to write
Git Git Git Git Git Git Git Git Git Git
Android Studio Git Widget — Interactive Base Change Tutorial
Git Commit Gitlab GitFlow Git Commit Gitlab GitFlow
introduce
While many geeks can easily use Git from the command line, there are cases where a GUI can really speed up the workflow.
There are many excellent Git GUI clients on the market
Examples include SourceTree, Tower, SmartGit, GitKraken
Over the years, I have been in contact with several companies, and almost all my colleagues use SourceTree, no matter it is Windows or Mac.
Although our title is a bit exaggerated, that doesn’t mean SourceTree isn’t easy to use. On the contrary, the software is very easy to use.
However, if we develop the software of IDEA series, I personally think the Git GUI of IDEA is more convenient, faster and easier to use. After all, the so-called IDE is an integrated development environment. It can be done in one window, so there is no need to make two software, especially the functions of SourceTree. Android Studio Git has almost all of them, as well as a lot of thoughtful features that SourceTree doesn’t, which we’ll cover in more detail below.
Function is introduced
The first entry is on the top toolbar
In fact, I rarely open this window, because many commonly used functions, such as Commit, Push, Update Project, etc., are opened by shortcut keys, and other functions are also opened by other portals.
You can do everything you need to do with Git from here, so here’s a quick overview of Android Studio’s built-in widgets.
Commit to submit
This interface is the one we deal with most at ordinary times. It is roughly divided into four areas when opened
For example, if I change two bugs at the same time, I will create two Changelist lists. Each list contains only the changes related to a particular bug.
This way, when I commit, each commit is cohesive and doesn’t contaminate the commit.
In the upper left corner of this area are some operations on files, such as modifying and comparing, rolling back files, refreshing lists, and viewing by category
② The area is for filling in the commit log. You can see that there are three buttons in the upper right corner, the last one is the latest log history
The first two are plugins I installed to help write a better standard log. Plugins will not be detailed, but first paste a picture, we will talk about it separately later.
This is much friendlier than the SourceTree/Git default contrast mode, but you can change it if you prefer it.
There are also some ignoring conditions, such as ignoring whitespace, when I only add a few whitespace, he will think there is no change. You can also choose to highlight content, such as lines, words, etc., which is very powerful. Generally, if we have integrated code review, for example, our company uses Jetbrains’ Upsource, we can also directly see colleagues’ comments on the code.
(4) area is before submit to us to do some operations, generally have the plug-in intervention, there will be more relevant content, the default has submitted before formatting code automatically, reorder code, optimize the import, code analysis, etc., can see is really very powerful, and deep integration IDE, with plug-in, one-stop service, very convenient.
Push Push
If your project has many submodules, you can submit them all together. If you use SourceTree, it’s more difficult to implement, at least not by default. What I have learned is that using SourceTree custom scripting features, running our scripts to push, undoubtedly adds a very large cost.
As shown in the figure below
The Update Project to Update
This one is relatively simple, we pull update, there are two choices, one is Merge, one is Rebase, as for the difference between the two, here is not detailed, unfamiliar can search, nuggets there are many excellent articles about very clear
I usually use Rebase for updates, which helps us keep a clean Commit record, and if you use merge, it’s easy to have too many merge paths.
The Merge with
The drop down box is used to select branches, that is, which branch to Merge the current branch into, and then when we Merge the command line, there are several additional parameters, such as –no-ff, –ff-only, to tell you the truth, If we don’t use these parameters very often, it’s easy to forget or misremember them. Android Studio has a drop-down list for you to choose from.
Rebase Rebase
Merge is basically the same as Merge, as long as the operator pays attention to what you are doing, after all, a lot of people do not use Rebase, I will explain more about Rebase in Android Studio later.
Management of Branches
This is one of the very basic features
We can see that we can create new branches and check out tags or specific versions
All local and remote branches are also listed below. If you select a branch, there are general operations for that branch
- Checkout Current branch
- Check for new branches based on this branch
- Branch contrast
- Compare the branch
- Rebase branch
- The merge branches
- Update the branch
- Push the branch
- Rename branches
- Delete the branch
New Branch Creates a Branch
Create a branch and fill in the name of the branch.
The New Tag play Tag
Also very basic function, fill in the corresponding information, our tag is ready.
Reset Head resets the code
This is a dangerous operation that is used to reset the code. The mixed parameters of git reset are also provided to the operator as a drop selection. Use with caution!
Show Git Log Displays commit logs
This opens up another, more powerful interface, which will be described later, where many of our daily and advanced operations are performed.
Patch patches
Here you can play Patch and apply Patch
This is a standard git diff generated patch pack, which is certainly much cleaner than the command line.
Uncommitted Changes Changes are not committed
Shelf is one of the highlights of Android Studio. Although it is similar to Stash in function, its ease of use and use are completely superior to git’s own Stash, which will be discussed in more detail later.
Current File
Is the action of the most active file in the current window, such as
- submit
- Add
- Display Blame details
- Display the Blame information by line
- Git diff = git diff = git diff
- Compare to a certain commit
- And branches
- Display the history of this file
Here’s a quick overview of what the menu can do. As you can see, Android Studio’s automatic GUI is already very powerful.
Normal operation
Let’s introduce the functional areas we have been dealing with at ordinary times
Local Changes Local Changes
The Local Changes interface is shown in the image above. Let’s take a look at the buttons on the left.
It’s going to be from the top down
- Refresh the file state, (sometimes we have some files are not tracked, or some files are not set to ignore, at this time, after the match, refresh it.)
- Submit the selected file
- Roll back the selected file
- Compare selected files (workspace vs. Index)
- For changelist management
- Hold the selected file (hold it in a second TAB, different from the stash file that comes with Git)
- File Classification Management
- View ignored files, etc
- A list of
- Shrinkage list
- Displays the specific content bar on the right
For the right file, there are some ah commonly used functions
Shelf Local temporary storage
Just to be clear, I think it’s a blast.
First of all, let’s talk about the difference between Git and its stash.
Shelve is a JetBrains product feature (e.g. WebStorm, PhpStorm, Android Studio, etc.). It puts shelved files into the. Idea /shelf directory.
Stash is one of the Git options. It places the stored files in the.git directory.
Let’s take a look at the effects of shelve and come to the conclusion.
When we shevle the first file activity_main2.xml in the Default Changelist, we shelve the entire Changelist that is still waiting to be continued.
Let’s go to the Shelf TAB.
The modification records of these two files were migrated from Local Changes to Shelf, which was managed by IDE for us.
At this time we need to reapply the time, just need to right-click in the need to restore.
You can see that we can restore not only the entire list, but also some files in a list individually.
It is used to temporarily store code and provide a clean environment for our workspace. However, the Shelf granularity is more detailed. If you use git Stash to stash5 files at a time, only 5 files can be recovered at the same time. In addition, the use of Git Stash is not very convenient, you need to type command line, and the default name such as change@1, change@2, very low recognition.
Therefore, I suggest that if the IDEA series software is used, Shelf can be completely used at this point, and the cumbersome Git Stash can be abandoned.
Log the git Log
This is the Android Studio git log view interface.
You can see that there are three columns on the left, middle and right, with the branch selection on the left, the route map for a branch in the middle, and the specific information for a selected commit on the right.
For a particular submission, let’s right click, there’s a lot of utility.
The green circle is the essence, many command line to knock a lot of command hot frequency operation, here have done integration.
For example, you can quickly modify a Commit Message. For example, quick to merge with a submission and very powerful interactive base change (this is also the essence, can be used to reposition our submission, merge and consolidate, etc.)
This is just a brief introduction, but I will elaborate on this interactive rebasing in this article.
conclusion
This article has taken a quick look at the features of Android Studio’s built-in Git widget, which is as good as any Git GUI on the market.
Because he is a built-in, compared to other software for us to write code, there is no doubt more conveniently, match again a variety of plug-in, we can realize we can think of almost everything and git related functions, that is one million times more powerful title I said reason, he besides its function perfect, still can use plug-ins do infinite possibility, Shirley is not bad!
Because this article is a little bit too long, some of the tips that I’ve used over the years, some of the tips that I’ve learned over the years, I’ve written separately, and I’ll give you the address at the beginning.
“Feel free to discuss in the comments section, nuggets officials will be onProject DiggAfter the event, 100 nuggets will be selected in the comments section. See the event article for details.