“This is the first day of my participation in the Gwen Challenge in November. Check out the details: The last Gwen Challenge in 2021”
git
Command quick
Liao Xuefeng git tutorial address: www.liaoxuefeng.com/wiki/896043…
Version back
HEAD
The version you point to is the current version, so Git allows you to run commands through the history of versionsgit reset --hard commit_id
.- Before the shuttle, use
git log
You can view the commit history to determine which version you want to fall back to. - To go back to the future, use
git reflog
Review the command history to determine which version to go back to in the future.
Undo modify
Scenario 1: When you tamper with the contents of a file in your workspace and want to discard the workspace changes directly, use git checkout — file.
Git reset HEAD
if you want to discard a file that you have changed in your workspace and added to the staging area, go back to scenario 1 and follow scenario 1 in step 2.
Scenario 3: An inappropriate change has been committed to the repository and you want to undo the commit, refer to the version Rollback section, but only if it has not been pushed to the remote repository.
ps:
Git checkout — readme. TXT git checkout — readme. TXT git checkout — readme. TXT git checkout — readme. TXT git checkout — readme. TXT git checkout — readme. TXT
One is that the readme. TXT file has not been placed in the staging area since the modification. Now, undoing the modification will return it to the same state as the version library.
One is that readme.txt has been added to the staging area and then changed, and now undoing the changes will return to the state after it was added to the staging area.
Return the file to the state it was at the last Git commit or git add.
Delete the file
To delete this file from the repository, run git rm and git commit:
$ git rm test.txt
rm 'test.txt'
$ git commit -m "remove test.txt"
[master d46f35e] remove test.txt
1 file changed, 1 deletion(-)
delete mode 100644 test.txt
Copy the code
You can easily restore the deleted file to the latest version because it is still in the repository:
$ git checkout -- test.txt
Copy the code
Git Checkout replaces the version in your workspace with the version in your repository.
Note: files that are deleted without ever being added to the repository are not recoverable!
ps:
The git rm command is used to delete a file. If a file has already been committed to the repository, then you never have to worry about deleting it by mistake, but be careful, you can only restore the file to the latest version, and you will lose what you changed since the last commit.
Associated remote warehouse
- To associate a remote library, use the command
git remote add origin git@server-name:path/repo-name.git
;
Git Git Git Git Git Git Git Git Git Git Git Git Git Git When associating a remote library, you must specify a name for the remote library. Origin is the default common name.
- After the association, run the command
git push -u origin master
Push all contents of the master branch for the first time
After that, you can push the latest changes with the git push origin master command whenever necessary after each local commit.
Git will not only push the contents of the local master branch to the new remote master branch, but also associate the local master branch with the remote master branch. The command can be simplified later when pushing or pulling.
Disassociate remote libraries
Git remote rm
git remote rm
git remote rm
You are advised to use git remote -v to check the remote library information.
$ git remote -v
origin [email protected]:michaelliao/learn-git.git (fetch)
origin [email protected]:michaelliao/learn-git.git (push)
Copy the code
Then, delete by name, such as delete origin:
$ git remote rm origin
Copy the code
In this case, “delete” actually unbinds the local and remote, not physically deletes the remote library. Nothing has changed in the remote library itself. To actually delete a remote library, log in to GitHub and go to the delete button on the background page.
Create merge branch
Speak address (good) : www.liaoxuefeng.com/wiki/896043…
Check out the branch: Git Branch
Git branch
Git checkout
Git checkout -b
Git merge
Git branch -d
Resolve the conflict
Website: www.liaoxuefeng.com/wiki/896043…
Bug branch
Website: www.liaoxuefeng.com/wiki/896043…
When fixing bugs, we fix them by creating new bug branches, then merging them, and finally deleting them;
When the work in hand is not finished, first put a git stash on the work site, then go to fix the bug, and then go back to the work site with a Git stash pop.
Git cherry-pick
if you want to merge a bug fix on the master branch into the current dev branch, you can use git cherry-pick
to “copy” the bug commit to the current branch.
Git rebase and Git Merge
The original address: www.jianshu.com/p/4079284dd…
Why not use Rebase for common branches? Because all of these new commits are new, everyone else that pulls out of this public branch needs to be rebase, so if you rebase things in, they’re all new commits
- 1-2-3 is now the branching state
- So this is the proD branch that comes out of the original master checkout
- Then the Master submitted 4.5 and proD submitted 6.7
- The master branch state is 1-2-3-4-5, and the PROD state is 1-2-3-6-7
- If you use the rebase master on PROD, the PROD branch state becomes 1-2-3-4-5-6-7
- If merge 1-2-3-6-7-8…….. |4 to 5|
- There’s going to be an 8, and the submission of the 8 is the submission of the 4 minus 5
Merge and rebase are really just waves of more colloquial interpretations of different scenarios. Rebase, for example, is a case where you develop your own branch and do it all the time, and then one day, you want to integrate the mainline changes into your branch and do an integration, so rebase is a good case. Put all your commits on the mainline. If you merge, Merge 8 on your head, if you want to go back to a commit on your branch, there’s another important question,rebase, originally my branch was pulled out of 3, after rebase, I don’t know where I pulled out of my development branch Similarly, if you use Rebase on the main branch, rebase changes on the other branches, is it true that if someone wants to see what history there is on the main branch, they’re not going to get the full history lesson, that history has been altered by you
Commonly used instructions
- Git rebase -i dev can merge the dev branch into the current branch. This means that you can interfere with the rebase process by setting a commit message, suspending a commit, and so on.
- Git rebase – Abort aborts a merge
- Merge multiple commit operations: 1 git rebase -i dev 2 Change the last few commit records to a pick squash. 3 Save the configuration and exit. Modify the commit record and save the configuration and exit git rebase –continue