The official manual
git-scm.com/book/zh/v2
Config Configuration file
/etc/gitconfig
Global configuration~/.gitconfig
或~/.config/git/config
User Configuration (Windows$HOME\.gitconfig
= =C:\Users\$USER\.gitconfig
).git/config
Project configuration- Partial configuration preferentially like CSS
git config --global user.name "Otao"
git config --global user.email "[email protected]"
git config --global core.editor "'C:\Users\enda\AppData\Local\Programs\Microsoft VS Code\Code.exe' --wait"
git config --list # list the current user configuration
git config --list --global
git config --show-origin [config] Show where the configuration came from
Copy the code
Help help
git help [verb]
git [verb] -h # or --help
Copy the code
process
- Warehouse (
repository
)git init
- Clone existing projects
git clone (https|git|ssh)://host/proj [localname]
Create in the current directoryproj
或[localname]
Folder)
- Start or stop tracing (
track
) filegit add [file|dir]
- The staging (
stage
) or submit (commit
)git commit -m 'comment'
- Ignores the specified file and file mode
- Undo bad operation
- Browse project’s
Version history
And different submissions (commits
) between thedifferences
- Push to remote warehouse (
push
) - How to pull from remote repository (
pull
) file
File status (untracked
| tracked
)
- Untracked =>
git add file
=> staged - Unmodified =>
edit file
=> modifiedgit rm file
=> untracked
- Modified =>
git stage
=> staged - Passage Ten =>
git commit
=> unmodified
git status # Check the current status
git status -s # --short View state simple mode
12 file # 1-> Staging area 2-> Workspace
M modified-unstaged.txt
MM staged-modified.txt
A staged.txt
M modified-staged.txt
?? untrached.txt
# commited
On branch master
Your branch is up-to-date with 'origin/master'.
nothing to commit, working directory clean
# uncommited
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
# unstaged
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
# untrached
Untracked files:
(use "git add <file>..." to include in what will be committed)
# unmerged
Unmerged paths:
(use "git add <file>..." to mark resolution)
both modified: index.html
Copy the code
Ignore files.gitignore
cat .gitignore
# comment lines
The glob pattern matches the default recursion
# / Prefixes prevent recursion
# End/specify directory
#! The beginning of the file does not ignore matching files in the ignored file*.[oa] *~ The glob pattern refers to the simplified regular expressions used by the shell. The asterisk (*) matches zero or more arbitrary characters; [ABC] matches any character listed in square brackets (this example matches either an A, a B, or a C); Question mark Matches only one arbitrary character; If a dash is used to separate two characters in square brackets, it indicates that all characters within the range of two characters can match (for example, [0-9] matches all numbers from 0 to 9). Two asterisks (**) are used to match any intermediate directory. For example, A /**/z can match a/ Z, A/B /z, or A /b/c/ Z.Copy the code
Git-scm.com/book/zh/v2/…
To view changes
git diff Modify the part after temporary storage
git diff --staged # -- uncommitted portion after cached
Copy the code
Commit changes
git status Passage 10 # Check unstaged files to check unstaged files
git commit Staged files Commit staged files
Open the editor to edit the submission instructions
git commit -m "Story 182: Fix benchmarks for speed" Submit directly according to the specified parameters
Copy the code
Delete the file
git rm file Delete files from staging and delete workspace files
git rm -f file Delete files from the repository
git rm --cached file Delete only files in the repository, keep workspace files, include non-essential files when ignoring file Settings
Copy the code
Move files
Because Git doesn’t automatically track file name changes, you need to move them explicitly
git mv a.txt dir\a.txt
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
renamed: README.md -> README
Copy the code
View submission History
git log Display all commit history in descending order
git log -p -2 # -- Patch displays all submission history and difference limits in descending order
git log --stat # Brief mode
git log --pretty=[oneline|short|full|fuller] Preformat output
git log --pretty=format:"%h - %an, %ar : %s" Custom formatted output
# This is especially useful when oneline or format is used in conjunction with graph, another log option. This option adds some ASCII strings to visually display your branching and merge history
git log --since=2.weeks # Last 2 weeks --until 2 weeks ago
git log --since=2008-01-15
Copy the code
Git-scm.com/book/zh/v2/…
Git remote
git remote # check the current repository (short shortname)
git remote -v # View the full warehouse link
git remote add pb https://github.com/paulboone/ticgit Add warehouse 'pb'
git fetch pb # pull download
git pull <remote> <branch>
git pull origin master
Copy the code
This command will only work if you have write permission to the clone server and no one has pushed it before. When you clone at the same time as someone else, and they push upstream and then you push upstream, your push will be rejected without question. You must grab their work and merge it into your work before you can push it.
git remote show origin View the current branch
Copy the code
Git branch branch
git branch # view branch
git branch -v View branch and commit information
git branch <new-branch>
git branch testing Create a branch
git log --oneline --decorate # see the HEADGit checkout <branch> Move the HEAD pointer to gitlog --oneline --decorate --graph --all # View fork history
git checkout -b <new-branch> Create and switch to a new branch
git branch --merged # view current branch to merge branches
iss53 # can be deleted
* master
git branch --no-merged # check the unmerged branches under the current branch
testing
Copy the code
HEAD
Pointer: Points to a reference branch, which creates branches down from its branch- Branching changes files in your working directory
Hotfix mode
git checkout master # Switch to main line
git checkout -b hotfix Create and switch to the Hotfix branch
[some changes]
git commit -a -m 'fixed bugs' Save and commit the changes
git checkout master # Switch to main line
git merge hotfix # Merge branches Move the current branch to its children
git branch -d hotfix Delete temporary branches
Copy the code
Git- Branch – New and merge branches
- Fast-forward (father-son inheritance)
- Merge commits multiple inheritance
Branch merge in case of conflict
<<<<<<< HEAD:index.html
<div id="footer">contact : [email protected]</div>= = = = = = =<div id="footer">
please contact us at [email protected]
</div>
>>>>>>> iss53:index.html
Copy the code
after
<div id="footer">
please contact us at [email protected]
</div>
Copy the code
After modifying the conflict
git add [conflict]
git status
git mergetool Or use graphical guidance to resolve conflicts
Copy the code
Git tag git tag git tag
Label push needs to be pushed manually
git tag -l "[filter|*]" # list tagsGit tag -a v1.29fceb02# Tag checksum of submissions [starting from 7 bits]
git tag -d [tag] # delete tag
git push origin [tag] # Push TAB branch
git push origin --tags # Push all unregistered tags
$ git push origin --delete <tagname> # Explicitly push delete tag updates
Copy the code
- Lightweight label
- Refer to branch
- Annotated with the label
- Label information, date, label, check code
Git tag-a v1.4-m "My version 1.4"
github
Command line to create a warehouse
echo "# [project-name]" >> README.md
git init
git add README.md
git commit -m "first commit"
git branch -M main
git remote add origin https://github.com/[user]-github/[project-name].git
git push -u origin main
Copy the code
Push existing items to the repository
git remote add origin https://github.com/[user]-github/[project-name].git
git branch -M main
git push -u origin main
Copy the code
Github SSH connection Generates RSA key pair registration
ssh-keygen -t rsa -b 4096 -C "your_comment" -f ~/.ssh/id_rsa -N "passphase" Generate the key pair OpenSSH
# private key ~ /. SSH/id_rsa
# public key ~ /. SSH/id_rsa. Pub
clip < ~/.ssh/id_rsa.pub Copy the public key to the clipboard
# github > login > setting > SSH and GPG keys > new SSH keys
git config --global user.name "Firstname Lastname"
git config --global user.email "[email protected]"
ssh -T [email protected] # test link
ssh -vT [email protected] # DEBUG test link
Copy the code
Git certificate store
- By default, you are asked for your username and password every time you connect.
- “Cache” mode stores credentials in memory for a period of time. Passwords are never stored on disk and are erased from memory after 15 minutes.
- The “Store” mode stores credentials in plain text on disk that never expires. This means that unless you change your password on your Git server, you never need to enter your credentials again. The downside of this approach is that your passwords are stored in your home directory in plain text.
git config --global credential.helper=[cache|store]
[credential]
# C:\users\username\.gitconfig
helper = store --file /mnt/thumbdrive/.git-credentials
helper = cache --timeout 30000
Copy the code
credentials