(1) git blame filename
The command displays the creator of the file name, as well as the final commit and timestamp.
。
(2) Git reflog
This command displays the information that the head pointer moves. He is local, not part of your warehouse. Will not be included in the push and merge. If I use Git log, the submission information I get is part of my warehouse.
。
(3) Git stash
Save your current changes in your workspace for the time being. The workspace then reverts to the state of the last commit. You can go and do other work.
git stash List
Displays the stash contained in the current workspace.
Git stash pop
Restores changes to the workspace while deleting the identifier.
。
(4) Cat ~/.gitconfig
View the current GIT user name and mailbox;
.
(5) Git cancels the workspace modification (not add,commit)
When we're writing code, maybe for some reason, we want to fall back to the original change, so what should we do? There are two ways of doing this:
"First Method"
1.git status
Shows which files have been modified.
2.git Checkout--filename
Discard changes to the workspace. (You can choose which files to roll back and which files to keep modified).
"The second Method"
1.git Reflog
View the information submitted each time.
2.git Reset--hard [Commit version value]
Forces a fallback to the previous commit version. (Discards all file modifications in the project, completely back to the previous commit version). You can add a commit version value, and you can fall back to any version. No [commit version value], default fallback to previous version.
(6) Git cancels the workspace modification (already add, not commit)
At this point we have added some changes to the local registers, but found that these changes are not necessary. The fallback is to be done. There are two ways of doing this:
"First Method"
1.git reset head [filename]
Empty the local registers. You can add a filename or no file name later. When the filename is specified, the modification of the file is emptied from the registers. When you use "Git Reset Head", you empty all file modifications. It is the same as the workspace modification, but it has not yet been added and has not been commit.
2. If you want to roll back to the previous commit, please refer to (5).
"The second Method"
1.git Reflog
Displays information for each submission.
2.git Reset--hard [Commit version value]
Rollback to any submitted version. As you can see from here, the "Git Reset--hard commit version" command is available at all times, and no matter how you modify the workspace or registers, you can go back to any version by using this command directly. Very strong, but also be careful.
(7) git RM filename
Deletes a file trace and deletes the file.
(8) git rm--cached filename
Deletes a file trace, but does not delete the file.
(9) Conflict resolution
A123
<<<<<<< head
b789
=======
b45678910
>>>>>>> 6853E5FF961E684D3A6C02D4D06183B5FF330DCC
C
Where I modified the <<<<<< (7 <) and ======= (7 =). ======= and >>>>>>> are modified by others. Find the conflict, we just need to modify the conflict, go back to the submission process.
(10) The code submission is not smooth
You may fail while Git is pushed, possibly because someone else has submitted the new code, and your code is in conflict with someone else's code. You need to git pull, modify the conflict code locally, and then add-->commit-->push the process.
(11) Modify the name of the branch
Maybe for some reason, you want to change the name of a branch, except for master, of course.
git branch-m Old branch name New branch name
。
(a) Git clone-b branch name Warehouse name
Like what:
git clone-b version1.4 Myrepo
Because of the iteration of the project version, we typically develop a new version of a branch that will be used when a team member is checked out or cloned from that new branch.
(13) Conflict Resolution: The conflict Code is as follows:
<<<<<<< Head
Test in Master
=======
Test in Dev
>>>>>>> Dev
Understand:
<<<<<<<: Marks the beginning of a conflict, followed by the contents of the current branch (also can be understood as the code you changed).
Head: Refers to the submission of the current branch.
After the,>>>>>>> is to merge the other branch of the code (also can be understood as the code that others changed).
>>>>>>>: The end of the mark conflict, the dev behind is the name of the other branch.
You just need to modify the conflicting code according to the requirements, and then continue add, commit, push. It is best to pull first before the push, so that the conflict is resolved locally.
() git clone remote All branches (here's a bit of a hassle, I'm going to talk about it).
git clone warehouse URL: Only the master branch of the remote repository can be clone, and all branches cannot be clone. If we want all the branches in the warehouse, the solution is as follows:
1. git clone repository URL;
2. Git branch-a: View all branches:
*master
Remotes/origin/dev
Remotes/origin/master
Understanding under: master[Local Main Branch], origin/master[remote Main branch, origin/dev[Remote Development Branch]
The Clone code default master and Origin/master are associated, which means their code stays synchronized. However, the Origin/dev Branch has no association locally.
You can see that the remote repository actually has the dev branch, but there is no local branch.
3. Git checkout-b dev Origin/dev: Create a new dev branch locally and checkout the remote Dev branch (associated with the Remote Origin/dev Branch) and switch to the Dev branch;
() git diff submit version hash value: File name Submit version hash value: file name
Compare the differences between two files in different submissions, and the version hash value can be obtained by the git log command, which requires a relative path.
() git log filename
To view a file's modified record, the file name requires a relative path.
() Git show submit version hash value
View all changes that were committed at one time, and the hash value can be obtained by using git log.
(%) git config--list
View the user name and password in the current git.
() git config--global user.name "Chenyufeng"
git config--global user.email "503434355@qq.com"
Add the username and password to modify Git, plus the--global parameter representation is the global setting. Note that the change can also be used with this command.
(20) The following figure is the use of GIT standard process, I found from the Internet map, painted very clear:
。
Reasonable and correct process:
Local to have a branch A and the distal branch to maintain the corresponding.
Then the local new branch b development, submit records.
If you need to push the code to the far end, switch to a, first pull the remote code on branch A.
Then merge the development Code on branch b onto branch A.
Then push to the server side.
(21) New branch: Each time you develop new features, you should create a separate branch.
#获取主干最新代码
$ git Checkout Master
$ git pull
# Create a new development branch Myfeature
$ git checkout-b myfeature
(22) sync with the trunk: during the development of the branch, keep the trunk in sync.
$ GIT fetch origin
$ git rebase origin/master
GitHub home: https://github.com/chenyufeng1991. You are welcome to visit.