Git command learning summary and work use

Git learning:
git branch XX creates a new branch.
git checkout XX switch branches.
git checkout -b XX creates a new branch and switches to the new branch.

git reset //Reset the branch pointer
1, --hard modify the file that does not exist, and there is no add, the pointer points to the reset node, after modification, add, commit.
2. The --mix modification still exists, but there is no added file. The pointer points to the reset node. After submitting to re-add, commit
3. After the node pointed to by the --soft HEAD pointer, the modified file is the same as the added file , still exists. Submit just commit

git branch 
git branch -D branch name //Delete branch.
git branch -m oldname newname //Modify the branch name.
git branch -vv //View the remote branch corresponding to the local branch.

If you create multiple branches locally, you want to merge the local branch b into branch a
git checkout a //switch to branch a
git merge b //merge branch b into branch a

Merge with the remote branch
git fetch origin //fetch the remote branch to the local
git merge origin/master //merge the remote branch into the local.
git reset --merge //Undo the merge.

git diff View the difference between the workspace and the temporary storage area

git diff --cached /--staged Compare the difference between the staging area file and the last commit

The pull and commit process used in the work

Workflow: (relatively simple, there is only one local branch)
1.repo sync or git remote update //Update the remote host
2.git branch -av //View the information of the last commit object of all branches
4.git reset --hard HEAD //Roll back to the version after the last synchronization of the remote host, and clean up the local machine
5.git clean -df //Clean up untracked files and folders, execute together with the previous command, basically the local machine Back to the status of the last commit.
6.git pull origin master:master//Synchronize the latest code of the remote host to the local branch, pull + merge
7. Modify.
8. git add
9. git commit -m
10. Before submitting, confirm whether someone has pushed first.
  git remote update
  git branch -av Check whether someone has pushed the remote branch first,
  if so, execute git reset --soft HEAD^ //The latest submission disappears, but the modification has not changed.
   git pull origin master:master 
   git commit -m //Resubmit
  and then push, if not directly push 
11.git push origin master//Submit the code to the remote host

*no branch problem:
      The code update script only specifies which remote warehouse to use, but does not specify which branch to use. After execution, it will
      appear that it is currently in the no branch branch. The no branch branch is not managed by git, so
      switch to the working branch and process it. Switch branches and execute git checkout -b newname
git push and report an error error: rejected –non-fast-forward
      Solution: This prompt indicates that the current submission cannot be fast-forwarded, which means that someone else has
      made other submissions to the remote end before you. The remote side requires you to commit on the latest basis.
      1. Merge git remote update  
      git pull to the latest code,
      git push.
     2. Resubmit
     git remote update
     git reset --soft HEAD^
     git pull
     git commit
     git push

 

おすすめ

転載: blog.csdn.net/liujing_sy/article/details/100542498