In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/03 Report--
1. Install git on centos
Yum install-y epel-release
Yum install-y git
Set the user identity, otherwise the initial use of the command will prompt
Git config-global user.name "silen"
Git config-global user.email "silen@huanglearn.cn"
two。 Create a version library
Mkdir / home/gitroot
Cd / home/gitroot
Git init / / initialize with this command to make this directory a repository that git can manage, configuration files and other files in the .git directory
3. Submit documents to the warehouse
1) echo-e "123\ naaa\ n456\ nbbb" > 2.txt / / create a file 2.txt
2) git add 2.txt / / add 2.txt to the warehouse
3) when git commit-m "add new file 2.txt" / / add is finished, you must commit to actually submit the file to the git repository and customize the description.
1) echo-e "ccc\ nddd" > > 2.txt / / change 2.txt first
2) git status / / check the status of the current repository, such as whether there are any changed files
3) git diff 2.txt / / can compare what 2.txt has modified this time. Compared with the version in the warehouse, an is online; b is local.
4) after git status / / modified the 2.txt file, check the status; prompt you to commit or discard the changes
5) git checkout-- 2.txt / / discard modification or restore deletion, and check the content again without change
6) before git add 2.txt / / commit again, you can also undo it
7) git reset HEAD 2.txt / / undo, back to the previous step
4. Fallback with log version
1) echo-e "eee\ nfff" > > 2.txt / / modifications are submitted for the first time
Git add 2.txt
Git commit-m "change once 2.txt"
2) echo-e "ggg\ nhhh" > > 2.txt / / modify and submit for the second time
Git add 2.txt
Git commit-m "change twice 2.txt"
3) git log / / you can view all the recorded operations submitted to git warehouse
4) git log-- pretty=oneline / / one line display, more clearly
5) git reset-- hard b0b97 / / according to this log, we can specify the first version of fallback, followed by a string that can be abbreviated.
6) git reflog / / when you fall back to a certain version, the later version of git log will no longer be displayed. Use this command to display all versions for further recovery.
5. Undo the modification
1) 2.txt has been modified or deleted, but there is no add. Use checkout to restore the status of the last submission.
Git checkout-2.txt
2) 2.txt has been modified or deleted, add, but not commit. Use reset HEAD first, and then use checkout to restore the status of the last submission.
Git reset HEAD 2.txt
Git checkout-2.txt
3) both add and commit, and use the version fallback method to restore the state of the last submission
6. Delete
1) cp 2.txt 3.txt / / create a new file and submit
Git add 3.txt
Git commit-m "add a new file 3.txt"
2) rm-f 2.txt / / Delete files in the version library
Git status / / you can see that the 2.txt file has been deleted
3) git checkout-- 3.txt / / if you want to recover, directly use
4) delete git rm 3.txt / / in the git repository. This step can be undone with reset HEAD.
Git commit-m "delete 3.txt" / / completely delete 3.txt
7. Make a remote warehouse (github)
1) https://github.com registers an account and creates its own git
Click repositories-- > new (custom name, such as studygit)-> Select public, click create repository
2) add key:
Click on your avatar in the upper right corner, select settings, and select SSH and GPG keys on the left.
Click New SSH key in the upper right corner and paste the / root/.ssh/id_rsa.pub contents on the linux machine here (generate the public key command ssh-keygen)
3) push the local reference to the remote warehouse
A. Mkdir / home/studygit
Cd / home/studygit
Git init / / initialization
Git remote add origin git@github.com:huangzp-silen/studygit.git / / the local study repository is associated with the remote study
B. echo "test,test,test" > test.txt / / create a file in the local warehouse directory and submit it
Git add test.txt
Git commit-m "create a new file test.txt"
C. Git push-u origin master / / remote push. You need to verify the prompt for the first connection; you can git push directly the next time.
D. viewed in github, it has been pushed successfully
e. Edit the test.txt, submit it in the local warehouse, and then push git push remotely
f. Clone a remote warehouse
A. Cd / home
Git clone git@github.com:aminglinux/lanmp.git / / Clone a remote repository to a local directory
B. Cd lanmp
Vi lanmp.sh / / Editing cloned files
Rm-rf. / git / / Delete the configuration file
Git init / / reinitialize the configuration file
C. git add lanmp.sh / / submit to local warehouse
Git commit-m "change lanmp.sh"
d. Log in to github and create a lanmp project
Git remote add origin git@github.com:huangzp-silen/lanmp.git / / synchronous association
Git push-u origin master / / and then push to the remote server
8. Branch management
Note: the master branch is basically unchanged (that is, it does not modify the file, but only does the merge). It is only when the test is completed that it is merged into master. Usually, the development branch is generally used, but it doesn't matter if you are wrong.
1) git branch / / View branches
Git branch silen / / create a branch
Git checkout silen / / switch branch, asterisk identification
2) under the silen branch, edit the 2.txt and submit to the new branch
Echo "silen" > silen.txt
Git add silen.txt
Git commit-m "create a new file silen.txt"
Git checkout master / / switch back to the master branch, look at the file, and do not find silen.txt
3) merge branches. In the process of development, it is often necessary to merge branches of multiple people.
Git checkout master / / first switch to the target branch that needs to be merged, such as master
Git merge silen / / merge the silen branch into the master, and only update the contents of the source branch (silen) file. The target branch (master) will not change even if it is changed, and generally will not change the master branch.
Note: both the master branch and the silen branch have edited silen.txt, which will prompt conflicts when merging. Method: under the master branch, edit silen.txt, change to the content of silen.txt in the silen branch, then submit silen.txt, and then merge the silen branch (or vice versa). There is a principle for merging branches. The newest branches are merged into the old ones.
4) Delete a branch
Git branch-d aming / / if the branches are not merged, the merge will be prompted before deletion
Git branch-D aming / / forcibly delete branches, that is, do not merge content before deletion, and data will be lost
5) principles of branch application
Master branch is very important, online distribution code with this branch, usually the development code is not on this branch, but to create a dev branch, dedicated to development, only before the release online, the dev branch will be merged into master. Developers should branch into personal branches on the basis of dev, develop code in personal branches (on their own pc), and then merge them into dev branches
9. Git stash keeps the site
When we edit a new file 4.txt in the silen branch, we need to go to another branch to repair a bug, so we need to keep the site. If not, every time (possibly another colleague) submits the branch, there will be a prompt for 4.txt to submit.
1) git add 4.txt / / submit, but do not commit
2) git stash / / Save the scene and hide the file
3) switch to another branch to repair bug, and then return to the silen branch after repairing bug
Git stash list / / View the saved scene
Git stash apply / / restore the scene, and the files are displayed back.
Git stash apply stash@ {1} / / restore can be specified
10. Remote branch
1) on web, you can create, switch, delete and restore branches.
2) View the remote library information, use git remote-v, and view the origin name. If the local branch is not pushed to the remote, it will not be visible to others.
View the remote branch git ls-remote origin through the name origin command
3) push the branch locally and use git push origin branch-name. If the push fails, grab the remote new submission with git pull first.
4) push files to the remote master branch
Synchronize files on web side
5) create a branch corresponding to the remote branch locally, and use git checkout-b branch-name origin/branch-name. The names of the local and remote branches should be the same.
Cat .git / config / / View the configuration file and get the remote URL for cloning
Rm-rf studygit/
Git clone git@github.com:huangzp-silen/studygit.git
Create a dev2 branch on web and synchronize locally
Git checkout-b dev2 origin/dev2
6) grab the branch remotely, using git pull
11. Label management
Tags are similar to snapshot functions, and we can tag the version library to record the status of a time library. We can return to that state at any time.
1) git checkout master / / cut to the master branch first
Git tag v1.0 / / label master v1.0
Git tag / / View all tags
Git show v1.0 / / display details
2) tag is tagged for commit, so you can type tag for historical commit
Git log-pretty=oneline-abbrev-commit
Git tag v0.9 46d3c1a
Git tag-a v0.8-m "tag just v1.1 and so on" 5aacaf4 / / can describe the tag
3) git tag-d v0.8 / / remove the tag
4) git push origin v1.0 / / push the specified tag to the remote
Git push-- tag origin / / push all tags
5) if you delete a tag locally, you need to do this if you want to delete it remotely:
Git tag v1.0-d
Git push origin: refs/tags/v1.0
twelve。 Skillful use of aliases
1) isn't the git commit command a little long? Using aliases can improve our work efficiency. / root/.gitconfig can be modified in the configuration file.
Git config-global alias.ci commit
Git config-global alias.co checkout
Git config-global alias.br branch
2) View git aliases using commands
Git config-- list | grep alias
3) Tips for querying log:
Git config-global alias.lg "log-- color-- graph-- pretty=format:'%Cred%h%Creset -% C (yellow)% d%Creset% s% Cgreen (% cr)% C (bold blue)% Creset'-- abbrev-commit"
4) cancel alias
Git config-global-unset alias.br
13. Set up git server
After all, github is public, and private warehouses have to be bought. So we can find a way to build a private one that is only used by our own company.
1) yum install-y epel-reales
Yum install-y git / / install git
Useradd-s / usr/bin/git-shell git / / add git users and set shell to / usr/bin/git-shell to prevent git users from logging in remotely. If you want to log in, usermod-s / bin/bash git
2) cd / home/git
Mkdir .ssh
Touch .ssh / authorized_keys / / stores the client's public key
Chown-R git.git .ssh
Chmod 700 .ssh / authorized_keys
3) set the directory to store the git warehouse, such as / data/gitroot
Mkdir / data/gitroot
Cd / data/gitroot
Git init-- bare sample.git / / creates a naked warehouse, which does not have a workspace, because the Git repository on the server is purely for sharing, so users are not allowed to log in directly to the server to change the workspace, and the Git warehouse on the server usually ends with .git
Chown-R git.git sample.git
Clone the remote repository on the client (self-pc)
The above operations are done on the git server. Usually, the git server does not require developers to log in to modify the code, it just acts as a server, just like github, the usual operations are done on our own pc.
1) put the public key on the client in the git server / home/git/.ssh/authorized_keys file
2) git clone git@ip:/data/gitroot/sample.git
At this point, you can generate a sample directory under the current directory, and this is the remote repository we cloned. When you enter this, you can develop some code, and then push it remotely; you also need to use it in conjunction with git lab graphics
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.