In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
How to use Git in Idea, aiming at this problem, this article introduces the corresponding analysis and answer in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible way.
IDEA synchronizes remote branch information
In the Idea view, the branch information of GIT is in the lower right corner. If we create a new branch in remote, it is not displayed locally by default. You can navigate above: VCS-Update project synchronizes the remote branch information.
IDEA create and switch local branches
In the GTI view in the lower right corner of IDEA, we can select branches for checkout, that is, create / toggle branches
If we need to specify which branch to create a new branch from, select the branch-checkout As in the GIT view to create a new branch
If we need to see which branch a branch is pulled from, we can use the command: git reflog show childBranch command to see
GIT command new / toggle branch-view current branch git branch-- based on a branch new branch git checkout original branch name-new branch and switch git checkout-b new branch name-then use git branch to view, branch has been created and toggle GIT command view / switch upstream branch
After we use the git checkout as branch, the branch tracks the checkout branch by default. We can use the command to view the upstream branch tracked by the current branch.
-- View the upstream branch of the current branch git branch-vv-- switch tracked upstream branch git branch-- set-upstream-to=origin/release_1001GIT command delete / restore branch
Delete
-- View the list of branches git branch-a muri-delete the local branch git branch-D branch name-delete the remote branch git push origin-- delete branch name
Restore
Deleted hash$ git branch-D devDeleted branch dev (was 1a103dd) will be displayed when deleted.-- restore delete git branch dev 1a103dd (branch hash) git remotely force overwrite locally
For example, if a file is deleted locally, it needs to be overwritten remotely.
Git reset-- the branch where hard origin/ is located. IDEA merge branch.
For example, we created a new dev branch from the test branch, and after making code changes on the dev branch, we need to merge the commit of dev into the test branch.
Git view Select test branch checkout switch to test
Project right: git-repository-pull updates test branch
Project right: git-repository-merge changes, select dev branch to merge
GIT undoes merge
Suppose we merge a branch, but we don't want to merge, and we want to undo the merge.
Git merge-- abortGIT chooses to merge a submission
Master pulls out branch dev and commits multiple times, so master needs to merge one of dev's commits (possibly an emergency bug fix).
-1. Switch to the master branch checkout master--2.git page to view the submission record (git log-n view the most recent n) git log-5 Murray 3. Choose to merge a commitgit cherry-pick 0601e177dd
Then normal pull > push will be fine.
GIT rebase
In general, if we need to merge code, we will use git merge, but another powerful feature is that rebase;rebase means that one branch is reset to another branch; this has the following benefits:
Rebase will display more clearly than merge node tree.
Rebase can reduce unnecessary commit information.
Comparison between merge and rebase
Suppose we have a branch master and then checkout a dev. Let's follow these steps to test it.
1.master modify and commit2.dev modify and commit 3.master modify and commit4.dev modify and commit
If our dev branch needs to be up-to-date with master to avoid invalid modifications, we need to merge the master code into dev.
/ / switch to the submission git rebase master of dev branch git checkout dev//dev branch synchronization master
The following figure shows how we compare the node tree display of merge (left) and rebase (right).
As can be seen from the above figure, the node tree after merge is sorted according to the submission time, while after dev resets the benchmark, the submissions of dev are displayed after master, thus keeping the submission information clear.
Rebase merge submission Information
Note that this situation is used in the case of local submission
Suppose there is a situation where I modified a bug,commit locally five times before fixing it, then if I put these push into remote, it will cause the gitlog to be very messy, in fact, the five submissions can be merged into one. In this case, we can use rebase to merge the local commit.
First of all, we submit 5 times locally. The git log is as follows:
Then we use git rebase-I to submit the ID (note that the id represents all submissions after merging the id, but does not include the id, so look forward if you need to)
Git rebase-I cf8525cd52c4bb87d3f11b4f721e6c1a8a3ac3f4
Then git will go to the vim page. We can press insert to enter the editing mode and enter the corresponding operation. Here are three parameters:
Pick: the comment that represents the merged submission with this submission
S: shorthand for the squash command, which means that the merge submission is included in the submission
D: represents the exclusion of this submission from the merge submission
After we change the parameters as needed, esc exits the editing mode,: wq writes and exits, and git moves on to the next step: fill in the merged commit message interface:
Similarly, we enter vim editing mode, comment out unwanted information, and modify the information submitted 5 times to bug fix 2 Magazine WQ to write and exit to complete the merge.
Finally, we looked at our five submissions and merged into bug fix 2 in the git command and the IDEA view, respectively.
Conflict between push and remote
Local modification is made, and then commit; as a result, when push, we find that remote has been modified. After we use the pull command, we will fail. At this point, we will prompt: You have not concluded your merge. (MERGE_HEAD exists) at this time we should:
Back up local data
Discard local modifications, remote reset local
Git fetch-all
Git reset-the branch where hard origin/ is located
Then manually merge the backed-up data locally and then submit it.
This is the answer to the question about how to use Git in Idea. I hope the above content can be of some help to you. If you still have a lot of doubts to solve, you can follow the industry information channel for more related knowledge.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.