The git syntax often used in the development process

1. Code submission steps

  1. git add . - add all files to the temporary storage area
  2. git commit -m 'test' - Submit the files in the temporary storage area to the local warehouse
  3. git pull origin master - pull remote code, master remote branch name
  4. If there is a conflict and the conflict is resolved, continue to repeat the above three steps
  5. git push origin master - push local changes to the remote master

2. The local code is wrongly written in the master branch. If the modification of the master branch is submitted to a new branch or other branches

1. git stash or git stash save 'note'

     Save the state of the current workspace and temporary storage area, save the current modification to the git stack, and restore it when needed later. The git stash command can be used multiple times, and a new stash@{num will be added every time it is used }, num is the number

git stash save 'comment' - you can follow the content you want to comment

git stash list - view the list of stash

2. git checkout -b dev —— Create a dev branch and switch to the dev branch

 git checkout dev - only switch branches, not create

 3. Take the stash in the git stack: git stash pop or git stash apply

git stash pop —— restore the latest stash@{num} in the git stack by default, it is recommended to use it when there is only one in the git stack to avoid confusion

Note: This command deletes the latest saved content in the stack

git stash apply - restore the contents of the stack to the current branch. This command is different from git stash pop. This command will not delete the content from the stack, that is, this command can apply the content of the stack to the working directory multiple times, which is suitable for scenarios with multiple branches

 After git stash apply, the changes in the stash of the git stack will be displayed in the dev branch

3. Version rollback

1. git reset --hard target version number

Mostly used for only commit, no push to remote

Note: reset is to roll back to the specified commit version, all commits after this commit will be cleared, and no records will be generated after reset is executed

step

1. git log - view the version number to be rolled back

2. git reset --hard target version number - version rollback

3. git push -f - push to remote

 Roll back the submitted 'test' 

go back

 push to remote

2. git revert target version version

It is mostly used for push to remote

revert only undoes the modification of the specified commit, and does not affect subsequent commits; revert uses a new commit to roll back the commit you want to roll back

step

1. git log - view the version number to be rolled back

2. git revert target version number - version rollback

 After git revert, a new version number will be formed to record the rollback operation

4. Continuously updating...

Guess you like

Origin blog.csdn.net/weixin_45291798/article/details/127941360