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

Second, use Git on a single machine, establish remote warehouse and clone remote warehouse.

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

Share

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

1. Use Git on a single computer

# yum install-y git# mkdir / data/gitroot# cd / data/gitroot# git init / / initialize the repository. After initialization, ls-la can see a .git directory in this directory. Write something at will, vim 1.txt# git add 1.txt / / add 1.txt to the warehouse and mark it # git commit-m "add 1.txt" / / add. Only when commit is finished can you really submit the file to the git warehouse. -m specifies the information for the explanation. The explanation must be written clearly. Error: * Please tell me who you are.Run git config-- global user.email "you@example.com" git config-- global user.name "Your Name" to set your account's default identity.Omit-- global to set the identity only in this repository.fatal: unable to auto-detect email address (got 'root@MRX. (none)') solution: # git config-global user.name "aming" # git config-global user.email "youjian" defines your name and email address. # git commit-m "add 1.txt" [master (root submission) 7e55239] add 1.txt 1 file changed, 5 insertions (+) create mode 100644 1.txt # git status / / View the status of the current repository, such as whether there are any changed files # there are no files to be submitted in the branch master, and the clean workspace changes the 1.txt again without adding it to the git repository. View status # git status # changes that have not been temporarily stored in the branch master# for submission: # (use "git add..." Update the content to be submitted) # (use "git checkout--..." Discarding workspace changes) # # Modification: 1.txt# changes have not been added to the submission (using "git add" and / or "git commit-a") # git diff 1.txt / / compare what has been modified this time. Diff-- git a/1.txt b/1.txtindex 958a6f4..100ff5b 100644-an Accord 1.txtcards + bUnip 1.txtbrands @-4 file changed 3 + 4 add 1.txt again 4 @ @ lehopigbnipa hjkasnklfejhuofj ioveripooabvo eovhsdidhbviabu+bviagb# git add 1.txt# git commit-m "add 1.txt again" / / submit the previously unsubmitted items to [master 7802c4f] qtxtsign 1 file changed 1 insertion (+) change the content of 1.txt again # git add 1.txt # git commit-m "ch 1.txt again" [master c3792d6] ch 1.txt again 1 file changed 2 deletions (-) # git log / / View all change records commit c3792d659aba7feae2be7e09337067bfbf14db76Author: aming// A name and mailbox are defined here Date: Sat Aug 31 20:38:58 2019 + 0800 ch 1.txt againcommit 7802c4fbfb41a3426aec1e224c6b3b56b746ebfdAuthor: amingDate: Sat Aug 31 20:37:12 2019 + 0800 add 1.txt againcommit 7e55239fcf6283f801b2bb44e4f4feb163ef9406Author: amingDate: Sat Aug 31 20:22:09 2019 + 0800 add 1.txt # cat / root/.gitconfig / / this shows the name and mailbox [user] Name = aming email = youjian# git log-- pretty=oneline / / display the content on one line the string before c3792d659aba7feae2be7e09337067bfbf14db76 ch 1.txt again / / is the version ID158eee38da7accb5da0abcf5d8dd4afb2d5a587c add 1.txt again7e55239fcf6283f801b2bb44e4f4feb163ef9406 add 1.txt [root@MRX gitroot] # git reset-- hard 158eee38 / / fallback version The string that follows can be the abbreviation HEAD is now located in 158eee3 add 1.txt again# git log-- pretty=oneline / / because the version has been backed back, so the later version does not have 158eee38da7accb5da0abcf5d8dd4afb2d5a587c add 1.txt again7e55239fcf6283f801b2bb44e4f4feb163ef9406 add 1.txt# git reflog / / View all historical versions You can restore to the later version 158eee3 HEAD@ {0}: reset: moving to 158eee38c3792d6 HEAD@ {1}: commit: ch 1.txt again7802c4f HEAD@ {2}: commit: add 1.txt again158eee3 HEAD@ {3}: commit: add 1.txt again7e55239 HEAD@ {4}: commit (initial): add 1.txt# git reset-- hard c3792d6git log-- pretty=oneline / / the later version will come back # rm-f 1.txt / / accidentally Deleted # git checkout-- 1.txt / / restore 1.txt if the 1.txt file has been changed After doing add but not commit, if you want to go back to the state of the last submission, you can use the command git reset HEAD 1.txt / / to give it the mark of add to remove the change from the temporary storage area after reset: M 1.txt then executes git checkout-1.txt / / to restore the content before modification, that is, to get back the latest files in the code base. Delete the file # git rm 1.txtrm '1.txt'# git commit-m "delete 1.txt" / / delete the library and submit it once. [master 742df99] delete 1.txt 1 file changed, 5 deletions (-) delete mode 100644 1.txt if you delete the contents in the library, and if you want to restore them, check the historical version of git log-pretty=oneline and go back to the previous version directly.

Second, establish a remote warehouse

[local project is pushed to remote]

1. First, register an account with https://github.com. Click sign in to log in again.

2. Create your own git, click the plus sign in the upper right corner, and then click new repository.

3. Customize the database name, such as apelearn, select public (public), and click create repository.

4. Add key key: click on your avatar in the upper right corner, select settings, and select SSH and GPG keys on the left. / / the purpose of adding a key is for authentication.

5. Click New SSH key on the right side, and paste the contents of ~ / .ssh/id_rsa.pub on the linux machine into key. This is the public key. If not, use the ssh-keygen command to generate.

6. Create an apelearn directory under the / tmp directory and enter the apelearn directory. Execute the command:

Echo "# apelearn" > > README.md

Git init

Git add README.md

Git commit-m "first commit"

# echo "# apelearn" > > README.md# git init initializes the empty Git version library and generates a .git directory after / tmp/apelearn/.git/// initialization, which can be seen by ls-la. # git add README.md# git commit-m "first commit" # git remote add origin https://github.com/yaoweiyaowei/apelearn.git / / push the contents of the current warehouse to the remote # git push-u origin master Username for 'https://github.com': yaoweiyaowei / / enter your GitHub username and password. Password for 'https://yaoweiyaowei@github.com': Counting objects: 3, done.Writing objects: 100% (3 bytes), 209 bytes | 0 bytes/s, done.Total 3 (delta 0), reused 0 (delta 0) To https://github.com/yaoweiyaowei/apelearn.git * [new branch] master-> master branch master is set to track the remote branch master from origin.

7. Push the local warehouse to the remote warehouse git remote add origin https://github.com/yaoweiyaowei/apelearn.git / / this step is to create a new warehouse apelearn remotely with the same name as the local one.

8. Git push-u origin master / / then push the local apelearn repository to the remote apelearn. After the push, refresh it in GitHub's apelearn warehouse, and you can see that README.md exists.

The next time you push it, you can git push it directly.

Test:

Write a 1.txt with random content.

# vim 1.txt# git add 1.txt# git commit-m "add 1.txt" # git push

Then go to GitHub and refresh in the warehouse and you can see 2.txt.

Third, clone remote warehouse

[clone remote project to local]

Open a warehouse in GitHub with a green icon that says Clone or download. Click on it, copy the link, and then go to the home directory to use the clone command.

# cd / home# git clone git@github.com:yaoweiyaowei/lanmp.git / / followed by the address of Git.

It prompts that a repository will be initialized under the current / home directory and a .git directory will be created.

If you haven't uploaded the public key to GitHub, you can clone the project and read it, but you don't have permission to write.

# cd lanmp# vim README.md / / just add something # git add README.md# git commit-m "change readme.md" # git push

When you refresh the GitHub warehouse, you can see the changes.

With regard to changing the content of the file on the server side, you need to pay attention to the different browsers. QQ Browser cannot recognize the content of the change and cannot change it, either Firefox or Chrome.

QQ Browser is gray here and cannot be changed. After the changes are submitted, you can see the changes again:

After the server changes the content, if you want to update the content of the client, use the command git pull to pull it down.

Git push is pushed to the server.

Git pull is pulled down to the client.

If you've never done a clone before, use the git clone command the first time you do it. SVN is checkout.

Summary:

Click on to use Git:

# yum install-y git

# git init / / initialize the repository

# git add 1.txt

# git commit-m "add 1.txt"

# git status / / View the status of the current warehouse.

# git diff 1.txt / / compared with the version in the warehouse, what has been modified this time?

# git log / / View all change records

# git log-- pretty=oneline / / display the content on one line

# git reset-- hard 158eee38 / / fallback version

# git reflog / / View all historical versions

# git checkout-1.txt / / accidentally delete the file, and then restore the file

# git rm 1.txt / / Delete files

# git commit-m "delete 1.txt" / / delete the contents in the library as well

Set up a remote warehouse:

1. Log in to GitHub

2. Create a database (git)

3. Add key ssh key

4. Initialize the repository under the corresponding directory of the client

5 、

Echo "# 11111" > > README.md

Git init

Git add README.md

Git commit-m "first commit"

Git remote add origin git@github.com:yaoweiyaowei/11111.git / / create a new warehouse remotely

Git push-u origin master

Clone the remote repository:

Git clone command to clone the remote project to the client. The subsequent usage is the same, git add,git commit.

Git push, push up.

Git pull, pull down.

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