This is my first blog post. I participated in the creation activity of gold diggers and started my writing path together.

It has been more than half a year since I transferred from SVN to Git. I have recorded the daily basic git workflow, hoping to help some friends who are new to Git.

preface

Before using Git in a real project I read a number of articles and acted on some online Git [Learn Git shoot sites]. But it was never a real project and didn’t grasp the essence of Git, let alone how to use it at work.

Later, when I encountered it in my work project, I was confused at first and didn’t know how to use it. Merge branches, resolve conflicts, develop across branches, roll back code, and so on. Now I can flexibly apply all the scenarios I would encounter in normal work. I hope I can help gyms in similar situations.

GitLens

Since I’m using the VSCode editor, the plugin library also has a very convenient plugin called GitLens.

The one on the left after the downloadbranchThere it is

  • Source code management
  • COMMITS
  • FILE HISTORY
  • BRANCHERS
  • REMOTES
  • STASHES
  • TAGS
  • SEARCH & COMPARE

Source code management

This section is the most frequently used module on a daily basis. Mainly used for commit, conflict resolution after merge, stash work content (for cross-branch development).

  • The modified files will be placed inThe workspace
  • The workspaceYou can add git add to the staging area.
  • Every time a git commit is committed, theThe staging areaTo form a complete submission recordcommit

Commit process

  1. Adds the workspace file to the staging area. The mouse on theTo change theAbove the bar, click+.ICONS will be allThe workspaceAdd the file toThe staging area. You can do it for each file if you don’t want to commit all of themTemporary storage manageClick on the right side of a single file+.Icon. (PS: Don’t panic if you add a file to the temporary storage area by mistake. Find the corresponding file in the temporary storage area and click on the right of the fileNo. -You can go back to the workspace.
  2. Perform the commit operation. After writing the submission record, place the mouse pointer over itSource code managementBar, click the buttonSquare rootTo complete the submission.

Cross branch workflow

Such a situation may be encountered in practical work. You are working on A feature in branch A, but suddenly there is an online bug that needs to be urgently fixed. You need to switch to the corresponding online branch branch B to fix the bug.

So normally we need to commit the changes to branch A first. But your work in the A branch is not completely finished, and you don’t want to submit A half-finished project because you are A perfectionist. Work content. Git Stash is the perfect solution to your problem.

Just place your mouse over the Changes bar and find the Stash All Changes button (the one with the + sign on the reset button). Click on it and Git will store All of your workspace and you’ll see an empty workspace. Now you can switch to branch B for exciting online bug fixes!

Finally, when you’re tired of fixing the bug, go back to branch A and retrieve the changes you saved (see picture below) : Click on the STASH bar, find your STASH, click on the Apply STASH button, and select Pop STASH from the popup box.

(The difference between Pop and Apply is that after Apply, the stash record will not be deleted. Pop will be deleted.)

COMMITS

The COMMITS column displays all COMMITS for the current branch, and you can view the changes for each commit.

Git reset

Type on the blackboard and underline

It is recommended to submit both workspace and staging content before rollback, if you don’t want the work content then forget it.

Commit right-click the version to which you want to roll back and select *Reset Current Branch to Commit. In the dialog box that is displayed, select Hard Reset.

Soft Reset rollback leaves the contents of the workspace (leaves)

The Hard Reset rollback discards the contents of the workspace! Discarded! Discarded! Discards are Hard Rest

git reflog

After git reset, git will maintain a clean commit tree to present to us. As a result, the version rolled back to is the latest commit of the branch. Git reset discard commit

Git reflog: git reflog: git reflog: git reflog: git reflog It’s all coming back! Git does not actually delete a single commit.

All you need to do is find the hash value of the version you want to go to (just copy the first 6 bits) and run git reset –hard commit

In summary, any commit in Git is optional. So forming a good commit habit is crucial!

Remaining modules

I’ll update you later

conclusion

These are some of the workflow I used to work with GitLens in VSCode.

You don’t have to worry about what tools to use, as long as you are familiar with how Git works, try it several times. The rest of the tools are well understood, and command line or SourceTree are easy to use