Git action notes 1. Create directory $ mkdir learngit $ cd Learngit&nbs p; 2. Change the new directory to warehouse $ git init 3. Add a file to the repository &N Bsp $ git add readme.txt 4. Submit one or more files together to the repository $ git commit-m "wrote a readme fil E " 5. View the status of the warehouse $ git status 6. See what changes have been made to a file & nbsp $ git diff readme.txt 7. View history $ git log (--pretty=oneli NE) 8. Fallback previous version $ git reset--hard head^ or git reset--hard 3628164&nb sp; 9. View used commands $ git reflog 10. Discard Workspace Changes &NB Sp $ git checkout-readme.txt 11. Undo changes to staging area, back to workspace $ git reset HEAD readme.tx t Remarks: Fallback modification summary: Scenario 1: When you mess up the contents of a file in your workspace, you want to discard the changes to the workspace directly (that is, Not add), use the command git checkout-file. Scenario 2: When you're not only messing up the contents of a file in your workspace, but also adding it to staging area, you want to discard the changes (that is, add but no commit), in two steps , the first step with the command git reset HEAD file, back to scene 1, the second step by scene 1 operation. Scenario 3: When you have submitted an inappropriate modification to the repository, you want to revoke this commit (that is, commit), using git reset--har D head^ or git reset--hard 3628164 for version fallback, but only if it is not pushed to the remote library. 12. Delete a file $ git rm test.txt Associated Remote Library step: to associate a remote library, use the command git remote add origin [email protected]:p ath/repo-name.git; After associating, use the command Git push-u Origin master to push all the contents of the master branch for the first time; Thereafter, after each local commit, you can use the command git push whenever necessary Origin master pushes the latest changes; 13. Associating a remote library $ git Remote add origin [Email protecte D]:jhscpang/learngiT.git (SSH is not very good, with the HTTPS version, see the next line is not very good, with the HTTPS version, see the next line) git remote add Origin https://github.com/ jhscpang/learngit.git 14. Push local content to remote server $ Git push-u origin MASTER&NBSP;&N Bsp 15. Cloning a local warehouse $ git clone [email protected]:p angchao620/gitskills.git (SSH is not very useful, Use HTTPS, see next line) $ git clone https://github.com/jhscpang/learngit.git 16. Create a branch $ git checkout-b dev remarks: Git checkout The-b parameter indicates creation and switching, equivalent to the following two commands: $ git branch dev $ git checkout dev 17. View current Branch &NBSP ; $ git branch 18. Switch pointsSupport $ git checkout master 19. Merge the specified branch to the current branch $ git Merg e Dev (default is fast-forward mode merge) (assuming the current branch is the Master branch, this command merges the Dev branch into the master branch) If you disable fast-forward mode use the following command: git merge--no-ff-m "merge with No-ff" dev (typically, when merging branches, if possible, Git uses fast forward mode, but in this mode, the branch information is discarded after the branch is deleted. If you want to force the fast forward mode to be disabled, GIT will generate a new commit at merge, so you can see the branching information from the branch history. ) 20. Delete Branch $ git branch-d de v Forcibly delete a branch: $ git branch-d dev 21. View Branch consolidation $ git Log--graph--pretty=oneline--abbrev-commit 22. Save on-site not yet submitted $ git stash&n bsp; 23. View Storage Locations $ git stash list 24. Restore storage content $ git stash pop or git stash apply remarks: (with git stash apply recovery, but after recovery, stash content is not deleted, you need to use Git stash Drop to delete; Another way is to use git stash pop, restore the stash content also deleted) 25. Restore storage content for a specified location $ git stash apply [email protected]{0} 26. View Remote Library information &nbs P $ git remote-v or git remote 27. When your partner is developing on the dev branch (not the master branch), it must be locally created and the branch corresponding to the remote branch &N Bsp $ git checkout-b dev origin/dev (if error, fix it: Git fetch origin) 28. Push branch from local &nbs P $ Git push origin branch-name 29. From a remote crawl branch $ git pull&nbs p; 30. Create a link relationship between a local branch and a remote branch resolve pull failure $ git branch--set-upstream-to=origin/dev dev& nbsp; 31. Create tags or Create labels with descriptions, specify the signature with-a ,-M Specify caption &NBSp $ git tag <name> or $ git tag-a v0.1-m "version 0.1 released" 3628164&nbs p; 32. See all tags or View tag information $ git tag&nbs P or git show <tagname> 33. Tag the history version &NB Sp $ git tag v0.9 <commit id> 34. Remove tags $ git tag-d v0.1&nbs P Remarks: (If the label has been pushed to the remote, to remove the remote tag is a bit of a hassle, first remove, &N Bsp $ git tag-d v0.9 then remotely delete, & nbsp $ git push origin:refs/tags/v0.9 &NBSP ; 35. Push a tag to a remote $ Git push origin <tagname> 36. OnceSex push all not yet pushed to remote local tags $ Git push origin--tags summarize: Multiplayer collaboration mode step: 1. First initialize the folder into a git local library $ mkdir testgit CD testgit $ git init 2. Associate a remote library with the local library & nbsp $ git Remote add Origin https://github.com/jhscpang/learngit.git &N Bsp 3. If you do not develop with the default master branch, create a new branch (such as the Dev Branch), and the new branch is associated with the corresponding branch of the remote library (because the local library is synchronized with the remote library at the end) $ git checkout-b dev origin/dev (if this is an error, use the command $ GIT fetch origin solution, and re-enter git checkout-b dev Origin/dev once) 4. (After successful, this is already On the Dev Branch), clone the contents of the remote library $ git clone https://github.com/jhscpang/learngit.git & nbsp 5. To filePerform actions (such as Vim test.txt), and then add the modified files from work to the local library staging area $ git add test.txt &NBS P 6. Submit the file of the staging area to the local vault $ git commit-m "add test.txt" 7. Push the branch of the local library to the branch corresponding to the remote library, implement sync $ Git push origin dev 8. If PU SH encountered a conflict, then pull the remote library's new content to local, and then modify the conflict, redo 5-7 steps $ git pull 9 If the pull error is no tracking information, the link relationship between the local branch and the remote branch is not created, and the following command is entered to resolve it, and then pull it again $ Git branch--set-upstream-to=origin/dev Dev
Share common commands for Git