git command line window common commands

git command line window common commands

Configure user name and mailbox

git config --list View configuration information
git config --global user.name="hello" Set user name
git config --global user.email="XXXX@qq.com" Set mailbox

git init initialization git Project (build) .git Directory (actually a hidden folder)

git clone Clone address clone remote warehouse

If the cloned library is private, you need to enter the account name and password
You can also control panel – > user account – > Manage windows credentials – > add common credentials – > configure git:https://gitee.com Account and password

Version library git stores a lot of configuration information and file version information
Staging area: in the index file in the version library

Workspace – git add – > staging area – git commit – > version Library

Status of files in git directory
Untracked untracked status
Tracked tracked status
Unmodified unmodified
Modified modified
staged

Local warehouse operations

git status View file status
git status -s Concise display of file status

git add File name adds the file to the temporary storage area (the file changes from red to green)
git reset HEAD The file name becomes non staged


git commit -m "Description of submission operation" (All modified documents must be added to the storage area before submission)
git commit No,-m An edit file will be opened and the submission instructions will be entered in the file 

git rm File name "delete file"( rm The operation directly stores the operation in the temporary storage area, and then directly submits the operation)

If you delete it manually, you need to delete it again git add File name and submit

Set git ignore list

adopt git Create a command window.gitignore File specifies the files and folders to ignore
 input *.class It means wrong class Manage the end of the file 
!aa.class Indicates exclusion aa.class

git log View operation records 

Remote warehouse information

git remote The command indicates whether to establish a connection with the remote warehouse. The result is origin Is the name of the remote warehouse
git remote -v Displays the details of the connected remote warehouse
git remote show origin View specific information of remote warehouse

Add remote warehouse

git remote add <shortname> <url> Add a remote warehouse and specify a short warehouse name
(The remote warehouse does not necessarily need to be consistent with the local warehouse, but it is recommended to keep consistent)
You can add multiple remote warehouses

Clone remote warehouse

git clone The warehouse address is to clone all the information in the warehouse

Remove remote warehouse

git remote rm Remote warehouse name (remove Association)

Fetching the latest version from the remote warehouse to the local warehouse will not automatically merge the data

git fetch  Getting the latest version of the remote warehouse does not merge files
1 gite init Initialize a local warehouse
2 git remote add origin/master Add a remote warehouse
3 gite fetch origin master Get the remote warehouse information sheet local warehouse, but it will not be merged into the workspace

·4 gite merge origin/master is merged into the workspace. At this time, the workspace will have the information of the remote warehouse

git pull Get the latest version of remote warehouse auto merge file
1 gite init Initialize a local warehouse
2 git remote add origin/master Add a remote warehouse
3 gite pull origin master Get the remote warehouse information sheet local warehouse, but it will not be merged into the workspace

ยท
gite pull origin master --allow-unrelated-histories
If you want to pull data when there are local files associated with remote files, you need to add -- allow unrelated history after pull
After admission, a log file will be opened by default, allowing you to enter operation information, directly wq save and close it

git push origin master Local master Branch push to remote warehouse

git commit -a -m "Note content "adds the modified information to the temporary storage area and submits it to the local warehouse

git branch

master Main branch git init Created by default master branch

Branches are divided into local branches and remote branches
git branch view local branch

git branch -r View remote branches
git branch -a View all branches

Create branch

git branch b1 Create a local branch named b1

Switch branch

git checkout b1 Switch to b1 branch

Push branch to remote warehouse

git push origin b1 Push b1 Branch to remote warehouse

Merge branch

Switch to master Execute under branch git merge b1 This way b1 merge to master Under branch

Two branches modify the same line of code in the same file, and then conflict when merging. After merging, the branch name after the command line will be one merging word,
And the results suggest that we need to solve this conflict. The way to solve this conflict is to open the file, delete the conflict ID, and then submit it

Delete local branch

git branch -d Branch name (you cannot switch to this branch when deleting a branch)
If the branch has development content and is not submitted to the remote warehouse, it will not be deleted at this time
 use git branch -D The branch name can be forcibly deleted

Delete remote branch

git push origin -d b2 

git tag

List existing tags

git tag

create label

git tag Tag name

View label information

git show tag

Push labels to remote warehouse

git push origin Tag name

Check out label

git checkout -b  [branch] [tag] Create a branch to point to the state of the label

delete a tap

git tag -d [tagName]

Delete remote Tag

git push origin: refs/tags/[tagName]	

ssh protocol

Code cloud supports two protocols. One is http One is ssh

At C: \ users \ administrator Open git command window in SSH directory, execute SSH keygen - t RSA, and generate public and private keys
Then put the public key into the public key setting in the code cloud

Undo method in git

git reset maset^ Back to previous submission
git reset master~3 Go back to the previous three submissions
git reset <commitId> Fallback to the specified submission location

git reset --hard maset ^ go back and throw away the files in the workspace and staging area
The staging area of both soft and git files will not be lost --
git reset --mixed maset ^ fallback and the workspace is not lost and the files in the staging area are lost
git reset – hard HEAD ^ indicates return of last submission, head indicates current ^ indicates last submission
git reflog view the log version information of fallback
Git reset -- before which fallback version does hard return

reset will not keep the commit record after retreat, and revert will keep the commit record
git revert is used in the same way as reset

git revert is more like a new commit (more recommended for team development)
Move the pointer more directly like reset

git log --oneline view the record and display it in one line

git revert --quit exit Undo mode

Keywords: git

Added by tommix on Fri, 04 Mar 2022 21:42:39 +0200