Git-----Usage Summary

Source: Internet
Author: User
Tags using git

I. Simple creation of a library

1.ubuntu environment--Download Git:sudo apt-get install git

mkdir ~/Watermelon
' Create Gitfile '

PS: Small Command--
Git status to view the status of the workspace.
git diff can see what's changed. ----git diff + < file name >

2.git version Fallback

Command:git reset--hard commit_id

git log View commit history

Git reflog view operation history

git diff HEAD -- readme.txt 可以查看工作区和版本库的区别。

2.1 For a file submitted only (add), no commit. The file was modified when it was added. How do I update the last content?

Method: First git add and git commit. Add the last file and then submit it again.

3.git undo Changes

3.1 When the contents of a file are found to be incorrect, just in the workspace. To withdraw the method:

Git checkout--readme.txt

3.2 When the content of a file is found to be incorrect, it is already in staging area. Method of Withdrawal:

Git reset HEAD readme.txt When the reset command fallback version. Head indicates the latest version.

3.3 When the content of a file is found to be incorrect, it is already in the repository. Recall method: Same as 3.2, fallback to the workspace version. Modified according to COMMIT_ID.

Removal of 4.git

git rm readme.txt

Git commit-m "remove test.txt"

If you delete the wrong one, you can return it.

Git checkout--text.txt

PS: The above command is only for files that do not have git rm and git commit.

If you are using Git rm. Need to start with git reset HEAD <file> git checkout--text.txt

If you are git rm and commit then there is no way to go back.

5. Remote Storage

5.1 ssh-keygen-t rsa-c " [email protected] " Use this command to place the generated public key on the remote repository.

A warehouse is also built on the remote repository (the warehouse name is the same as the local warehouse name). Associates the local warehouse with the remote repository.

git remote add origin [email Protected]:wdgarden/waterwelon.git the name of the Repository is Origin

Push all local content to the remote library.

Git push-u Origin Master

The git push command actually uses the master of the current branch to the far end. Direct with command later: Git push Origin master

5.2 git clone [email protected]:wdgarden/watermelon.git

6. Create and Merge Branches

When a new branch is created. When you point head to dev again.

When a new commit is made on the dev branch.

Finally, the work on Dev is done. Merge to Master. Finally, you can also delete the dev branch.

git checkout-b Dev to create the branch and switch to Dev's branch.

When the content is modified on the Dev branch and the work is submitted, Git checkout master is cut back to the master branch. Then the file is still unchanged. Because that's the commit on Dev's branch.

Merge branch git merge dev

Delete branch git branch-d dev

PS: Common problems:

6.1 When the same file was modified on two branches respectively, and committed at the same time. As shown in.

This is not the time to merge. You can modify the content after the add and commit. As shown in.

Question: Here is the file modified on the main branch. Is there any change in the content that was modified on the dev branch? Do you need a merge once for no change?

Another way to merge branches:

git merge --no-ff -m "merge with no-ff" dev

Bug Branch:

Git stash Features: Save the current Job site.

Feature Branch:

When a new branch is created, the content of the commit is also made. Then you want to delete this branch.

Git branch-dfeature-vulcan

Git friendly reminder, feature-vulcan branch has not been merged, if deleted, will be lost changes, if you want to forcibly delete, you need to use uppercase -D parameters.

7. Multi-person Collaboration:

When you clone from a remote repository, git actually automatically corresponds to the local branch master and the remote master branch, and the default name for the remote repository is origin .

Use git remote -v to display more detailed information

推送分支:git push origin master

When another person clones this library, your little buddy can only see the local master branch.

Your little partner to develop on the dev branch, you have to create a origin remote dev branch to local, and he uses this command to create a local dev branch:

git checkout -b dev origin/dev

He can dev then continue to modify, and then, from time to time, dev branch push to remote:

git add a.txt

Git commit-m ' a.txt '

git push origin dev

Your partner has origin/dev pushed his submission to the branch, and you happen to have modified the same file and tried to push it:

git add b.txt

Git commit-m ' b.txt '

Git push Origin Dev

Send failed, because your small partner's latest submission and you are trying to push the submission has conflict, the solution is also very simple, git has prompted us, first with the git pull latest commit from origin/dev scratch, then, in the local merge, resolve the conflict, and then push:

Git pull

git pullAlso failed because there is a link to the remote branch that does not specify a local dev branch origin/dev , depending on the prompt, the setting dev and origin/dev the link:

git branch --set-upstream-to=origin/dev dev

Git pull

This is git pull successful, but there are conflicts in the merge, which need to be resolved manually, and the workaround is exactly the same as the resolution conflict in branch management. After resolving, submit, and then push:

git commit -m "fix env conflict"

git push origin dev

 

Git-----Usage Summary

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.