Common scenarios for GIT usage

Posted by rdennisak on Sun, 23 Jan 2022 05:01:52 +0100

I Git Foundation

1.1 three scopes of GIT

git config --global user.name 'your_name'

git config --global user.email 'you_email@163.com'

The default is local

git config  --local  *local It only works for a warehouse*

git config --global  *global It is effective for all warehouses of the current user*

git config --system  *system Valid for all logged in users of the system*

Display the configuration of config and add – list

git config --list --local
git config --list --global
git config --list --system

1.2 build Git warehouse

Two scenarios

  1. Bring the existing project code into Git management
cd Folder where the project is located
git init
  1. New projects are directly managed with Git
cd A folder
git init your_project # A folder with the same name as the project is created under the current path
cd your_project

If the git permission is global, create a new warehouse here and set the permission to local, then the last effective permission is local

Put in staging area

git add Files placed in the staging area 1 file 2
git add -u # All files

Put version history

git commit -m'Submit information'

1.3 view version history

1. git log                         # View all submissions of the current branch
2. git log --oneline        # Introduction view submission information
3. git log -n2 --oneline # View the last two commit s
4. git log --all                   # View log s for all branches
5. git log --all --graph      # Graphically display all branches
6. git log --oneline --all
7. git log --oneline --all -n4
8. git log --oneline --all -n4 --graph

git branch -v view how many branches are there locally

git checkout -b temp create branch

1.4 Git graphical management interface

gitk

1.5 .git directory

. git file directory

•	COMMIT_EDITMSG
•	config current git Configuration file for
•	description (Description information of warehouse (file)
•	HEAD (Point to the current branch, for example develop Branch, the actual pointing address is refs/heads/develop
•	hooks [folder]
•	index
•	info [folder]
•	logs [folder]
•	objects [folder] (Store all git Object. The first 2 bits of the object hash value are used as the folder name and the last 38 bits are used as the object file name, Can pass git cat-file -p Command, splice folder name+File name (view)
•	ORIG_HEAD
•	refs [folder] 
      •	heads (Store all branches of the current project)
      •	tags (All labels of the current project stored, also known as milestones)

•	cat Command, function: used to display files. for example cat text.md display text.md Contents of the document
•	ls -al Command to list all files in the current directory (including hidden files)
•	git cat-file -t Commands, viewing git Type of object
•	git cat-file -p Commands, viewing git Object content
•	git cat-file -s Commands, viewing git Object size

1.6 split head pointer

detached HEAD - this means that an unknown branch has been switched. This state will not be displayed in git after commit. git will be cleared automatically in the future. At present, the commit can be saved through the original branch name of git branch new branch name

Create a new branch based on a branch git checkout - b new branch name basic branch name

Git diff HEAD ^ 1 HEAD ^ 1 = = HEAD ~ 1 ` ` HEAD11 = = HEAD ~ 2 ` compare the comparison submitted by HEAD and his father ^ 1 represents his father and 11 represents his grandfather

II Common scenarios for personal use of Git

2.1 viewing branches

git branch -av

2.2 how to delete unnecessary branches

Git branch - D branch name if the branch does not have a merge, the command is invalid. To delete it, use git branch - D branch name

2.3 how to modify the latest commit message

git commit --amend

2.4 how to modify an old commit message

git rebase -i father-commmitID

Note that the variable base is implemented in a separately developed project and cannot be used in team development

2.5 merge successive commit s into one

Git rebase - I father commitid, change the last few commands to s

2.6 merge discontinuous commit s into one

Git rebase - I father commitid, put the to be merged together with the first one

2.7 comparison between temporary storage area and HEAD file

git diff --cached

2.8 compare the files in the work area with those in the staging area

Comparison of all files in git diff workspace and staging area

git diff filename comparison between the workspace and staging area of a file

2.9 restore the staging area to the same status as HEAD

git reset HEAD

2.10 restore the work area to the same as the staging area

git checkout -- filename

2.11 restore some files in the staging area to the same status as HEAD

git reset HEAD -- filename1 filename2

2.12 eliminate several specified submissions (the staging area and work area return to a certain location)

git reset --hard commitID

2.13 comparison of different branches and differential display of submitted documents

git diff branch-name1 branch-name2 -- filename

git diff commit-ID1 commit-ID2 -- filename

2.14 method of deleting files

git rm filename

2.15 temporary stoppage emergency tasks in development

Put git stash tasks on a stack

git stash list query task

Git stack apply copies the tasks at the top of the stack and can be used indefinitely

Git stack pop pops up the task at the top of the stack and uses it intelligently once

2.16 how to specify files not managed by git

vi . Put files that do not need to be managed in gitignore

Topics: git