38 Fundamentals of Git

Source: Internet
Author: User

1. Download git?
Git-scm.com

2. Get Help
Git help
git help config

3. What is Git?
Versioning, version control system, VCS. It allows us to commit changes to the source control repository and track changes. Allows Develope to work together on the same set of code libraries. is a modern, distributed version control system.

4, some key words?
Branch
Merge
Commit: Occurs on a local
Push
Pull

5. History of Git
Founded in 2005, the first Linux kernel used BitKeeper as a version control system, later Linus Kernel and BitKeeper split, BitKeeper's own company can no longer provide free services, Linux needs a new version control system instead of Bitkeeper,linux's handlers began to reinvent the wheel and later perfected the community, and was born on GitHub.

6. CVS and DVC?
CVS is centralized version control, where programmers submit to the same central server; DVC is distributed version control, everyone has their own code-controlling library, each commit is submitted to the local, Each time a new version of the code is submitted, then push to remote. A scenario for multiplayer collaboration: A and B work together, a commits the code locally, B is pull from the local code base of a, and when a completes the stage, push to the remote code server, B can now pull the code from the remote code base.

7, some orders?
Init, creating a local code base
Status, the state of the local code base, showing no commit changes
Add, put the file in the local code base
Commit, commit the changes to the local code base
Log, showing all changes to the commit
Push,push all changes to the remote code server and can also be submitted to multiple places
Pull, change from remote code server or other code base pull
Merge, merging changes

8. Git configuration

git config--global user.name "Darren"
git config--global user.email "[Email protected]"
git config--global--list

The information is stored in the. gitconfig file in the Administrator folder, which is roughly:
[User]
Name = Darren
email = [email protected]

git config--global core.editor note which editor to use
git config--global help.autocorrect 1 prompt when an error command occurs
git config--global color.ui auto set font color, etc.
git config--glboal core.autocrlf false under Windows recommended

The above settings are at the system level.

You can also set user-level, user-level overrides at the system level.

git config user.name "Jack"

User level removal settings: git config--unset core.autocrlf

9. Create a local code base, append files, commit changes

→ Go to a folder, open a command-line window
→ Create a local code base
Git init
→ Create a README.txt file within the folder
→ View the status of the local code base
git status
A red font indicates a file that has not been tracked
→ Add files to the local code base so that the files can be
git add README.txt
Git add-u is used to add files that have just been updated, not just the files that were added
Git add-a Add all files to staging area is track waiting to be commit
At this point, running Git status,readme.txt turns green, indicating that it has been track
→commit Change
Git commit
→ View History
git log

10. Historical version and version difference

→ View historical version
git log
→ View version differences
Git diff dd6819. A15ec6
→ View recent versions of history
git diff HEAD
→ View versions prior to the latest historical version
git diff head~1
→ View the differences between the recent history version and the previous version
git diff head~1..head
can also be written
Git diff head~1.

11, one time to modify multiple submissions

→ Assume that 2 files have been modified
README.txt
File.txt
→ View status
git status
You can now see that the modified file is in a red state. It's usually a commit, but it's a two-time commit.
→ First time add
git add file.txt
→ First commit
Git commit-m "Blablabla"
→ Second add
git add README.txt
→ Second Commit
Git commit-m "Second Blablabla"

12. Delete Files
→ Delete file.txt file
→ View status
git status
Deleted file.txt and is a red font
→ Put the deletion in staging area
Git add-u
→ View status
git status
Deleted:file.txt and is a green font
→commit
Git commit-m "Blablabla"

In other words, for deleted files, you also need to use Git add-u to put the deleted files in staging area.

13. Renaming files
→ Rename the file.txt to Newfilename.txt
→ View status
git status
Deleted:file.txt Red Font (the renamed file appears to git as a deleted state)
Nefilename.txt Red Font (new file appears to Git as a untracked state)
→ put deleted status files and new files on staging area
Git add-a
→ View status
git status
Renamed:file.txt→newfilename.txt Green Font (GIT records the rename process)
→commit, please.
Git commit-m "Blablabla"

14. Cancellation of Changes
→ Modify a file, such as README.txt
→ View status
git status
Modified:README.txt Red Font
→ Undo changes
git checkout README.txt

15. Undo Multiple Changes
→ Modify a file, such as README.txt
→ Delete a file, such as Newfilename.txt
→ View status
git status
Modified:README.txt Red Font
Deletedl newfilename.txt Red Font
→ Undo these 2 changes
Git reset-hard
→ View status
git status
Back to the nearest head.

16. Delete Files
→ Create file
Temp1.txt
Temp2.txt
→ View status
git status
Temp1.txt Red Font
Temp2.txt Red Font
→ Delete files
Git clean-f

17. Ignoring files
→ Suppose you create a logs folder and a log.txt of a line face
→ View status
git status
logs/Red Font
→ Create a. gitignore file with the following content:
/logs/*.txt
/logs/*.log
→ View status
git status
. Gitignore Red Font
→ Put the. gitignore file in staging area
git Add. Gitignore
→ Submit
Git commit-m "Added. Gitignore"

18. Copy Remote website to local
→ Copy
git clone https://github.com/jquery/jquery.git
→ View all Submissions
git log
git log--oneline

19. View Data
→ See the total number of submissions
git log--oneline | Wc-1
→ View with icon
git log--oneline--graph
→ See who submitted which
Git shortlog
→ See which people and messages
Git Shortlog-sne
→ View more
On the GitHub website, for example, there is a graphs menu with more detailed information.

20. View Submissions
→ Show Last Commit
Git show HEAD
→ Show Countdown Second Commit
Git show head~1
→ Show All Submissions
git log--oneline
→ Show last 10 changes
Git show head~10
→ Show a single commit
Git show 5642626
→ View Remote
Git remote
Origin remote name code base for Origin
→ View Remote More
Git remote-v
Origin Https://github.com/jquery/jquery.git (Fetch)
Orgin Https://github.com/jquery/jquery.git (push)

21. Git Protocol

GIT supports HTTP, https, git, ssh, and file protocols
The default port for HTTP is 80,https and the default port is 443, which can be set
For example on GitHub Web site, usually read is free, but write usually need password
GIT protocol
Git 9418 git://github.com/jquery/jquery.git
SSH protocol
SSH [email protected]:jquery/jquery.git
File protocol
File N/a/users/james/code/jquery

22. Viewing branches and labels
→ View Local Branch
Git branch
→ View Remote Branch
Git branc-r
→ View Tag
git tag
You can see all versions

23. Copy the local code base to remote, create the code base remotely
→ Create a remote code base on the local codebase
Git remote add Origin https://github.com/Darrenji/example.git

24. From remote FETCH
→fetch
git fetch
Pull all remote changes to the local
→fetch a Branch
Git fetch origin

25, remote changes synchronized merge to local
→ Remote has a change, there may be another programmer to submit
→ Sync Merge to Local
git merge Origin/master

26, from the remote pull
→ View Remote Branch
Git branch-r
Origin/master Red Font
→ Now ready to pull pull,pull equivalent to: git fetch; git merge Origin/master
→ Establish a remote and local mapping
Git branch--set-upstream Master origin/master The first master refers to a local
→ Start pulling
Git pull

27. Push to remote
→ Local commit some changes
Git commit-am "BlaBla"
→ Push
git push
Enter user name
Enter password

Of course, you can also delete a remote before pushing
→ Delete Remote
Git remote RM origin
→ List Remote
Git remote-v
→ Re-create a remote SSH protocol
git remote add origin [email protected]:D Arren/example.git
→ Push
git push

Note: The SSH protocol uses SSH key to authenticate users here

28. Create a label
→ Create a label
git Tag v1.0
Git tag-a v1.0_with_message
Git tag-s v1.0_signed
→ List all labels
git tag
→ List A label
Git tag-v v1.0_signed

29. Push the label to the remote
→ Git does not push tags by default
git push--tags

30. Visualize Branches
→ View commits under an existing branch
git log--graph--oneline
→ View commits under all branches
git log--graph--oneline--all--decorate
--all All Branches
--docorate such as Head,tag, etc.

You can also put the above options to the global and use the alias call:
→ Global Settings
git config--global alias.lga "log--graph--oneline--all--decorate"
→ Use the new command
Git LGA

31. Create a local branch
→ Create a local branch
Git branch Feature1
→ Jump to feature1 this branch
git checkout Feature1
→ View commits under all branches
git log--graph--oneline--all--decorate

32. Differences between branches and labels
Branch will follow Commits,tag always follow a commit.

→ Create a branch and let it follow a commit
Git branch fix1 974b56a
→ Switch to fix1
git checkout fix1
→ Modify a file under Fix1
→ Submit
Git commit-am "BlaBla"

33. Renaming and deleting branches
→ Rename Branch
git branch-m fix1 bug1234
→ Delete Branch
Git branch-d bug1234
→ Want git to report the deletion of the branch
Git branch-d bug1234
→ Create and switch to the newly created branch
Git checkout-b feature2

34. Get the deleted branch back
→ Enter as follows
Git reflog

5a78c8b [Email protected]{3}: commit:fixed bug#1234
→ Find Branch
Git branch bug1234 5a78c8b
→ Switch to the recovered branch
git checkout bug1234
→ Show head
Git show HEAD

Note: The commit period is only 30 days

35, do not submit changes hidden changes
→ Modify a file, such as README.txt
→ View status
git status
Modified:README.txt Red Font
→ Hide changes
Git stash
→ View all changes that are hidden
git stash List

36. Create a remote branch
→ Push to a branch on the remote
Git push Origin Master
→ Push local branch to remote
Git push Origin v1.0_fixes
The remote will have one more branch
→ View Remote Branch
Git branch-r

37. Delete Remote Branch
→ First push to remote branch
Git push Origin v1.0_fixes
Git push origin v1.0_fixes:v1.0_fixes_remote_branch_name (remote and local branch names are different)
→ Delete Remote Branch
git push origin:v1.0_fixes_remote_branch_name

38. Git Site Settings
Usually on git sites, such as GitHub, Coding.net will have some basic settings in place.



38 Fundamentals of Git

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.