Change submitted action
Another feature of Git is the flexibility to manipulate historical versions. With the advantage of decentralized warehouses, historical versions can be operated without affecting other warehouses.
Retrospective historical version
Next, we will establish a branch feature-B on the original version to illustrate the operation of change submission (as shown in the figure below).
Go back to before creating the feature-A branch
By command
git reset --hard *
Trace back to * version, as shown in the figure below
Create feature-B branch
Create a branch feature-B, for readme Modify the MD file and submit it, as shown in the figure below.
The status of the current branch feature-B is shown in the branch diagram.
Advance to the merged state of feature-A branch
The git log command can only view the history log ending with the current status. So here
To use the git reflog command, view the operation log of the current warehouse.
implement
git reflog
View the operation log of the warehouse, as shown below
(base) kevinkk@kevinkk:~/Desktop/new_study$ git reflog 44b9963 (HEAD -> feature-B) HEAD@{0}: commit: feature-B version d3c1eee (master) HEAD@{1}: checkout: moving from master to feature-B d3c1eee (master) HEAD@{2}: reset: moving to d3c1eee54745357214151f53c2885c3b89b13f6a d3c1eee (master) HEAD@{3}: reset: moving to d3c1eee54745357214151f53c2885c3b89b13f6a 135f04a HEAD@{4}: merge feature-A: Merge made by the 'recursive' strategy. d3c1eee (master) HEAD@{5}: checkout: moving from feature-A to master 6dfa875 (feature-A) HEAD@{6}: checkout: moving from master to feature-A d3c1eee (master) HEAD@{7}: checkout: moving from feature-A to master 6dfa875 (feature-A) HEAD@{8}: checkout: moving from master to feature-A d3c1eee (master) HEAD@{9}: checkout: moving from feature-A to master 6dfa875 (feature-A) HEAD@{10}: commit: Add feature-A d3c1eee (master) HEAD@{11}: checkout: moving from master to feature-A d3c1eee (master) HEAD@{12}: commit (initial): Initial version
In the log, we can see the execution records of Git commands such as commit, checkout, reset and merge. As long as Git's GC (Garbage Collection) is not carried out, you can freely retrieve the recent historical status through the log, just like assigning a time point to the time machine to shuttle freely in the past and future. Even if the developer mistakenly executes the Git operation, it can basically use the git reflog command to restore to the original state.
Switch back to the master branch and trace back to the historical state before restoring the trace back,
git checkout master git reset --hard 83b0b94
As shown in the figure.
Merge feature-B
Next, we merge the feature-B branch.
Conflict resolution
implement
git merge --no-ff feature-B
The system prompts conflict information after discovery
(base) kevinkk@kevinkk:~/Desktop/new_study$ git merge --no-ff feature-B Auto merge Readme.md Conflict (content): Merge Readme.md Auto merge failed. Correct the conflict and submit the correction result.
Open readme with an editor MD file, you will find that its content becomes the following.
master <<<<<<< HEAD feature-A ======= feature-B >>>>>>> feature-B
We change it to what we want in the editor.
master feature-A feature-B
The log information is shown below
Modify submission information
We marked the previous submission as "Fix conflict", but it is actually the merging of feature-B branches. Resolving the conflict during merging is only one of the processes. Such marking is really inappropriate. Therefore, we need to modify this submission information.
git commit --amend
After executing the above command, the editor will start.
Fix conflict # Please enter a submission description for your change. with '#'the beginning row is ignored and an empty commit # Description will terminate the submission. # # Date: Sun Apr 17 10:25:37 2022 +0800 # # In branch master # Changes to be submitted: # Modified: readme md #
Change the part of the submitted information to Merge branch 'fix-B', then save the file and close the editor. The changed log information is shown in the following figure.
References: [1] (Japan) hiroji Otsuka Github introduction and practice [M] Beijing: People's Posts and Telecommunications Press, 2015