Distributed version control tool -- Git

This paper simply records various commands and functions used in personal learning git.

Do not know where to download the small partner can directly portal https://git-scm.com/

After downloading and installing Git, the right-click menu will add two options (set when installing Git)

git init project creation

Just find a disk (D,E,F,G, etc.) to create a new folder, enter the folder, then right-click the menu Git Bash, and finally execute the command (git init).
At this time, we have created a local warehouse, which is essentially created in the current directory git folder (it is hidden, how to display the hidden folder).

//Project creation command
git init  

get into. After the git folder, the following directory appears

git clone pull remote object to local

Pull the object created from the remote end to the local, and point the HEAD to the pulled branch.

//By default, a folder with the same name as the version library is created in the current directory and the version is downloaded to this folder
git clone <Web address of remote warehouse>

//Specify the directory of the local warehouse
git clone <Web address of remote warehouse> <Local directory>

//-b specifies the branch to be cloned. The default is the master branch
git clone <Web address of remote warehouse> -b <Branch name> <Local directory>

git add adds a file to the staging area

Create an object for the file, and write the file and object hash into the index file through git update index.

//Adds the specified file to the staging area
git add <File path>

//Add all modified and deleted files to the staging area
git add -u [<File path>]
git add --update [<File path>]

//Add all modified, deleted and newly added files to the temporary storage area. Omitting < file path > is the current directory
git add -A [<File path>]
git add --all [<File path>]

//View all modified, deleted but not submitted files and enter a sub command system
git add -i [<File path>]
git add --interactive [<File path>]

git commit submits the staging area file to the local warehouse

Will The changes (additions, deletions and modifications) recorded in the git/index file generate tree objects (not necessarily tree objects, just examples) through git write tree, create a commit through git commit tree, point to some tree objects, and modify the branch reference to point to this commit object.

//Submit the files in the temporary storage area to the local warehouse, and call the text editor to enter the description of the submission
git commit

//Submit the files in the staging area to the local warehouse and add description information
git commit -m "<Description information submitted>"

//Submitting all modified and deleted files to the local warehouse, excluding files not tracked by the version library, is equivalent to calling "git add -u" first
git commit -a -m "<Description information submitted>"

//Modify the last submitted description
git commit --amend

git push submits the local object to the server

By referencing the specification, push the branch reference of this to the branch reference of the remote server, and the HEAD of the server always points to the master branch.

//Push the branch of the local warehouse to the specified branch of the remote warehouse
git push <Alias of remote warehouse> <Local branch name>:<Remote branch name>

//Deletes the branch of the specified remote warehouse
git push <Alias of remote warehouse> :<Remote branch name>
git push <Alias of remote warehouse> --delete <Remote branch name>

git pull pull pull server object

Pull the commit object and reference object of the server ahead of the local warehouse to the local warehouse, and update them according to the reference specification git/refs/remotes / branch, for local branches and The git/refs/remotes / branch performs the git merge operation.
Generally speaking, this command can merge the latest version of the server into the local branch.

//Get the latest version from the remote warehouse.
git pull

git branch create branch

Create a branch in git/refs/heads creates a directory to store the commit hash of the branch referenced by the current HEAD

//List all local branches, and the current branch is marked with "*"
git branch

//List all local branches and display the last submission. The current branch is marked with "*"
git branch -v

//Create a new branch based on the last commit
git branch <Branch name>

//Modify branch name
//If the original branch name is not specified, it is the current branch
git branch -m [<Original branch name>] <New branch name>

//Force modification of branch name
git branch -M [<Original branch name>] <New branch name>

//Deletes the specified local branch
git branch -d <Branch name>

//Force deletion of the specified local branch
git branch -D <Branch name>

git checkout switch branch

Switch branches, change the contents of the HEAD to the specified branch path, and point the HEAD to a commit, but it will cause problems. In short, checkout is to modify the direction of the HEAD

//Switch to the specified branch that already exists
git checkout <Branch name>

//Create and switch to the specified branch and keep all submission records
//It is equivalent to the combination of "git branch" and "git checkout"
git checkout -b <Branch name>

//Create and switch to the specified branch and delete all submission records
git checkout --orphan <Branch name>

//Replace the local changes, and the newly added files and contents that have been added to the staging area will not be affected
git checkout <File path>

git merge merge branch

Merge the commit forked on the branch with the commit pointed to by the current branch, generate a new commit, and point the current branch to this commit

//Merge the specified branch under the current branch
git merge <Branch name>

git reset restore committed records

Modify the commit pointed by the branch, which is also the difference between it and checkout. reset changes the direction of the HEAD by modifying the branch, while checkout directly modifies the direction of the HEAD.

//The staging area is reset, but the files are not affected
//It is equivalent to withdrawing the contents updated to the staging area with the "git add" command from the staging area. You can specify the file
git reset [<File path>]
git reset --mixed [<File path>]

//Change the direction of HEAD to the specified submission record, and the file is not modified
git reset <commit ID>
git reset --mixed <commit ID>

//Change the direction of HEAD to the specified submission record, and the file is not modified
//It is equivalent to calling the "git reset --mixed" command and then doing "git add" again
git reset --soft <commit ID>

//Change the direction of HEAD to the specified submission record, and the file is also modified
git reset --hard <commit ID>

git project is completely migrated, including all branches, labels and logs.

Download the project to be migrated first, and XXX will be generated after success Git folder.
Then enter this folder.
Then execute the third line of command (now saved in the local warehouse)
Finally, push to the new git warehouse

The code is as follows:

git clone --mirror  git@xxx.in.xxx.com:xxx/xxx.git
cd  xxx.git
git remote  set-url origin  git@xxx.in.xxx.com:xxx/xxx.git
git push -f origin

Keywords: Java git github

Added by Catharsis on Sun, 19 Dec 2021 05:38:22 +0200