preface

Git, as a widely used code hosting software, is much more convenient than SVN. Since the project team switched from SVN to Git in October last year, git has been used in the actual development process for some time. Compared with my previous experience in school where I could only use git bash to conduct git operations on the command line, I still learned and summarized some git graphical interface operations in the IDEA corresponding to git commands, which felt quite convenient. Here are some personal summary of the operation.

First, branch management

1. Branch switchover

Git bash:

git checkout branchName
Copy the code

The IDEA of operation:

2. Create a branch

2.1 Create a branchname-2 local branch from Branchname-1

git bash:

Git checkout branchName-1 git checkout branchName-2Copy the code

The IDEA of operation:

2.2 Associating a new local branchName branch with the remote branchName Branch

git bash:

git pull
git checkout branchName
Copy the code

The IDEA of operation:

3 Branch Deletion

Git bash:

Git branch - d branchNameCopy the code

The IDEA of operation:

Delete remote branches:

git bash:

Git branch -r-dOrigin/branchName // Notice there's a space between origin and the colon, Git push origin: branchName git push origin: branchName git push origin: branchName git push origin: branchName git push origin: branchNameCopy the code

4 Branch merge, branchname-1 merges branchname-2

git bash:

git checkout branchName-1
git merge branchName-2
Copy the code

IDEA operation: Switch to branchname-1

Code rollback

1. Roll back the workspace code

git bash:

git checkout givenFile
Copy the code

The IDEA of operation:

Roll back a single file

Roll back the code snippet

2. The local branch rolls back to the historical version

git bash:

git logGit reset -- hard Commit ID git reset -- hard Commit IDCopy the code

The IDEA of operation:

3. The remote branch rolls back to the historical version

git bash:

git logGit reset -- hard Commit ID // Rollback the local branch git push-fOrigin branchName // Force push to remote branchCopy the code

Stash function

Git Stash is used to keep current work progress. A common scenario is to urgently fix a serious bug in the Release branch while developing a branch development feature. At this point, you can store the current changes (uncommitted code) in the cache using a Git-stash pop, switch branches to fix bugs, and come back to retrieve the changes from the cache using a Git-Stash pop.

git bash:

Git stash Git Stash Save "Message... Git stash list git stash pop git stash popCopy the code

The IDEA of operation:

Fourth, submit view (bug tracking) function

IDEA -> Version Control -> Log, you can specify the branch, submitter, time, file or folder to view.

1. View the submission records of a file

git bash:

git log workSpace/src/main/java/javaop/BaseOpTest.java
Copy the code

IDEA operation: right click in the code file space

2. View the modification history of a line of code

git bash:

/ / - L s, e said the first lines s first e git blame -l 1100 0 workSpace/SRC/main/Java/javaop/BaseOpTest JavaCopy the code

IDEA operation: right click in the code file space

5. Merge multiple commits into one

As shown here, there are multiple Bugfix commits for the same bug. I want to combine them into one commit.

  1. Open the log history of IDEA

  2. Right-click commit record 3(the last commit to merge) and select Copy Revision Number to Copy commit ID

  3. Go to VCS->Git->Rebase, check Interactive, and paste commit from step 2

  1. Click Rebase and in the interactive Rebase menu, select the first one as pick, squash the rest and press Start Rebasing

  1. Edit the merged Commit message in the Additional Rebase Input and click Resume Rebasing

  1. Okay, finished commits are merged

Everybody see officer, feel summary of a bit of use, dot praise bai ~

reference

  1. www.zhihu.com/question/56…
  2. Blog.csdn.net/qq_32452623…