git operation

1. git init creates a local library in the current folder (add .git folder)

2. git add command to add files to the staging area

3. The git commit -m "<message>" command commits the files in the staging area to the current branch of the local library, such as 1.0

4. Submit several times, such as 2.0, 3.0, 4.0; use git log to view all versions and corresponding submitted messages (1.0, 2.0, 3.0, 4.0); use git log --pretty= (oneline, etc.) command to view specified information

5. The git reset HEAD^ command can be used to roll back from the current version, such as 4.0 to 3.0; the git reset HEAD^^ command can be used to roll back two versions from the current version, and so on; git reset HEAD~3 can be used to roll back 3 A version number, that is, rollback from 4.0 to 1.0;

  but:

  Using the git rest HEAD class command, after the version is rolled back, the workspace file (that is, the file seen on the hard disk) is still the latest, not the rolled-back version content.

  At this point, you can add the parameter --hard to roll back the workspace file to the specified version, git rest --hard HEAD command

6. At the same time, the git reset --hard version number command can be used to roll back to the specified version, but if the version has been rolled back before, the version after the rollback version will not be visible by using git log. For example, after rolling back from 4.0 to 2.0, Then use git log to check the version, you can only see the version 1.0 and 2.0,

  At this point, you can use the git reflog command to view all local repository operation information

 

7. Create a repository in the github remote library. You can use git remote add origin <remote library address> to add files to the remote end, but you have to use the git push -u origin master command to submit files to the remote end.

  The –u parameter is used in the first push, which means that Git will push the content of the local master branch to the new remote master branch, and it will also associate the local master branch with the remote master branch. Commands can be simplified by taking time

  After that, if there are changes, you can directly git push origin master to submit to the remote end.

8. You can use git clone <remote library address> to download the remote library to the local.

  origin is the default name of the remote repository

 

9. View branch: git branch

  Create a branch: git branch <branch name>

  Switch branches: git checkout <branch name>

  Create + switch branches: git checkout –b <branch name>

  Merge a branch into the current branch: git merge <branch name>

  Delete branch: git branch –d  <branch name>

 

The basic common commands of Git are as follows:

  git init turns the current directory into a manageable git repository and generates hidden .git files.

  git add XX adds the xx file to the staging area.

  git commit -m "XX" Commit file -m is followed by comments.

  git status View repository status

  git diff XX to see what the XX file has modified

  git log view history

  git reset --hard HEAD^ or git reset --hard HEAD~ go back to the previous version (if you want to go back to 100 versions, use git reset --hard HEAD~100 )

  git reflog View the version number id of the history

  git checkout -- XX undo all modifications of XX file in the workspace.

  git rm XX delete XX file

  git remote add origin <remote warehouse address> associates a remote library

  git push -u (use -u for the first time, it is not needed after that) origin master pushes the current master branch to the remote library

  git clone  <remote repository address> clone   from remote repository

  git checkout –b dev creates the dev branch and switches to the dev branch

  git branch View all current branches

  git checkout master switches back to the master branch

  git merge dev merges the dev branch on the current branch

  git branch –d dev delete the dev branch

  git branch <branch name> create a branch

  git stash hides the current work and resumes work after restoring the scene later

  git stash list to see a list of all hidden files

  git stash apply restores hidden files, but the contents are not deleted

  git stash drop delete files

  git stash pop deletes files while restoring files

  git remote View information about remote libraries

  git remote -v View the details of the remote library

  git push origin master Git will push the master branch to the remote branch corresponding to the remote library

  git pull origin master grabs the remote master content to the local library

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325539595&siteId=291194637