Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Git learning

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

1. Install and configure Git (system: Windows 10 64-bit)

1. Go to the Git official website to download and install.

two。 The Git configuration file for each warehouse is the .git / config file, and the current user's Git configuration file is the .gitconfig file in the user's home directory. Run "Git- > Bash" to configure the following: (--global indicates that these commands are useful under all Git repositories on this computer, and if not added, only works for the current warehouse)

$git config-- global user.name # specify user name $git config-- global user.email # specify email address $git config-- global color.ui true # Let Git display different colors appropriately

3. Ignore Fil

The files that need to be ignored are generally those that are placed in the Git working directory and cannot be submitted, including files automatically generated by the operating system, intermediate files generated by compilation, executable files, and their own configuration files with sensitive information.

At this point, create a .gitignore file at the root of the Git workspace, and then fill in the names of the files you want to ignore, and Git will automatically ignore them. GitHub has prepared various configuration files for us, and you only need to combine them to write .gitignore files.

$vim .gitignore # create .gitignore file (class Linux) $git add-f # force the addition of ignored files $git check-ignore-v # check .gitignore 's ignore rules for this file

4. Configure alias

$git config-global alias. $git config-global alias.

After setting up, you can use the git operation directly.

Aliases can be deleted by modifying the [alias] field of the configuration file.

Second, create a version library (Repository)

1. Create an empty directory to store the version library:

$mkdir $cd

two。 Initialize the version library using Git

$git init

3. Add the file to the version library (first make sure the file is in the same directory as the version library)

$git add $git add # put all changes to be submitted in the Stage/Index $git / *. # add all files (of specified type) under the specified directory $git add-- all # add all files under the current directory... $git commit-m # submit all changes to the staging area to the branch at once

III. Version management

$git status # View the current status of the workspace $git diff # View the specific changes $git reset-- hard # fallback to the specified version based on the previous version number, where HEAD represents the current version $git log # View the submission history to determine which version to go back to $git reflog # View the command history to determine which future version to go back to $git checkout-# undo the changes to the workspace Restore the mistakenly deleted file to the latest version (replace the workspace version with the version of the version library) $git reset HEAD # undo changes to the staging area $git rm # remove the file from the version library

Fourth, use Github to manage Git remote warehouse

1. Create a SSH key:

$ssh-keygen-t rsa-C

The generated private key and public key are stored in the id_rsa and id_rsa.pub files of the .ssh directory in the user's home directory, respectively.

two。 Go to GitHub,Settings- > Add SSH Key- > paste the contents of the id_rsa.pub file in the Key text box-> Add Key. Because Git supports the SSH protocol, GitHub can confirm through your public key that only you can push and identify that the submission you pushed is indeed yours.

3.Create a new repo- > fill in Repository name- > Create repository to create a new Git repository.

$git remote add origin git@github.com:/.git # associates a local library with a remote library (faster using the git protocol supported by ssh) $git remote add origin https://github.com//.git # associates a local library with a remote library (using the https protocol) $git push [- u] origin master # pushes all the contents of the local library to the remote library (- u for the first push The default name of the remote repository is origin) $git clone git@github.com:/.git # Clone a remote repository locally

4. The working mode of multi-person collaboration

$git remote [- v] # View remote library information (- v shows origin addresses that can be crawled and pushed) $git checkout-b origin/ # create a branch corresponding to the remote branch locally $git branch-- set-upstream-to=origin/ # establish the association between the local branch and the remote branch $git push origin # push the branch from the local (if the push fails Then you need to grab the remote new commit first) $git pull # grab the latest commit in the remote library (merge, resolve the conflict first and then push again if there is a conflict)

5. Participate in open source projects

Open source project repository-> "Fork" that is, clone to your own account-> "git clone" clone to local-> modify and push to your own remote library-> initiate pull requset to wait for open source project library to accept

V. Branch management

$git branch # View branch $git branch # create branch $git checkout / git switch # switch branch $git checkout-b / git switch-c # create and switch branch $git merge [--no-ff-m] # merge a branch into the current branch (--no-ff indicates that Fast forward mode is disabled, deleting a branch in this mode loses branch information After disabling, you can see the branch information from the branch history) $git branch-d # delete the branch (an error will be reported if the branch is not merged) $git branch-D # forcibly delete the branch $git log-- graph [--pretty=oneline-- abbrev-commit] # View the branch merge figure $git stash # Save the current work site $git stash list # View the saved work site list $git stash apply [stash @ {}] # restore the work site without deleting the stash content (restore stash 0 by default You can also restore the specified stash based on stash_id) $git stash drop # delete stash content $git stash pop # restore work site and delete stash content $git cherry-pick # copy specific submissions to the current branch $git rebase # organize the local non-push bifurcation submission history into a straight line

When Git cannot automatically merge branches, the conflict must be resolved first, that is, the file that failed to merge with Git must be manually modified to what you want to submit, and then submitted and merged.

VI. Label management

$git tag # View all tags $git tag [- a] [- m] [commit_id] # tagged (the default is on the latest submission of the current branch, or it can be tagged according to commit_id, and-a specifies the signature -m specify description text) $git show # View tag information $git tag-d # Delete tag $git push origin # push a local tag $git push origin-- tags # push all unpushed local tags $git push origin: refs/tags/ # Delete a remote tag

Finally, the portal of the source of learning is attached: the Git course of teacher Liao Xuefeng on Git's official website.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report