git usage record

Posted by j4ymf on Wed, 24 Jun 2020 05:38:18 +0200

In short, it's not very appropriate to talk about several git partitions

Workspace: all the files you currently see are actually workspaces
 Staging area: after running git add, the changes to the working area will arrive at the staging area
 Version area: after running git commit, changes to the staging area will arrive at the version area
 Remote: the submission running git push local version will be pushed to remote warehouse

git bundle usage, package code base

Package git Library

git bundle created aa.bundle HEAD <branch,tag,commit>

Check which versions are in the packed git Library

git bundle list-heads aa.bundle

Check bundle file availability

git bundle verify aa.bundle

You can use git clone to directly clone out the packaged code and submission records

git clone aa.bundle

git push usage

Push said some branches to the far end

git push -u origin --all

Push all tag s to the far end

git push -u origin --tags

Commit code to remote

# Submit local master to remote master
git push origin master:master

# Increase the price from local test to test
git push origin test:master

git remote

#View remote warehouse
git remote -v
#Add remote warehouse
git remote add [name] [url]
#Delete remote warehouse
git remote rm [name]
#Modify remote warehouse
git remote set-url --push [name] [newUrl]

# Name is the warehouse name, and the default is origin

git branch

#View local branch
git branch
#View remote branches
git branch -r
#Create local branch
git branch [branchname]
#Switch branch
git checkout [branchname]
#Create a new branch and switch to it now
git checkout -b [branchname]
#To delete a branch, the - D option checks whether the commits in the branch have been merged into other branches, if not prohibited. Force delete using the - D option
git branch -d [branchname]
# Both of the following are mandatory deletion
git branch -D [branchname]
git branch --delete --force [branchname]
#Merge branch, merge the branch named [name] with the current branch
git merge [branchname]
#Create a remote branch
git push origin [branchname]
#Delete remote branch, push an empty to remote
git push origin :heads/[branchname]
gitpush origin :[branchname]

git tag

#View version
git tag
#Create tag
git tag [tagname]
#Delete tag
git tag -d [tagname]
#View remote Tags
git tag -r
#Create remote version
git push origin [tagname]
#Delete remote version
git push origin :refs/tags/[tagname] or git push origin :[tagname]
#Merge remote warehouse tag s to local
git pull origin --tags
#Upload local tag to remote warehouse
git push origin --tags
#Create annotated Tags
git tag -a [tagname] -m 'v2.2.2.2'

git checkout

#Create split and switch to the branch
git checkout -b [branchname]

#Changes to restore work
 . is to restore all work
git checkout .
git checkout path

#Switch, tag, commit
git checkout [branchname, tagname, commitid]

git diff comparison difference

 #Compare the differences between the workspace and the staging area
  git diff
  #Compare the differences between staging area and version Library
  git diff --cached
  #You can see the differences between workspaces and version Libraries
  git diff HEAD
  # Compare differences between two branches, commit and tag
  git diff name1 name2
  # There are... Fewer submissions for name1 than name2
  git diff name1...name2

git show view the submitted content (git reflog can view all operation records of all branches, including the deleted commit records and reset operations)

# View a submission
git show commitid

git log

git log --pretty=oneline --decorate=full

#--"Pretty = format: options after"% H "format"
#Option description
# %H the complete hash string of the commit object
# %h short hash string of submitted object
# %Full hash string of T-tree object
# %Short hash string of t-tree object
# %Full hash string of P parent
# %p short hash string of parent
# %an author's name
# %E-mail address of ae author
# %ad author revision date (format can be customized with - date = option)
# %ar author revision date, as of how long ago
# %cn name of the committer
# %E-mail address of the ce submitter
# %cd submission date
# %cr submission date, as of how long ago
# %s submission instructions
#There are other options
# --stat displays the file modification statistics for each update
# --since, --after shows only submissions after the specified time, -- since=2.weeks
# --Until, - before shows only commits before the specified time
# --Author only displays submissions related to the specified author
# --committer displays only submissions related to the specified committers
# --grep searches for keywords in the submission description. If you want to get a submission that meets the search criteria of these two options at the same time, you must use the --all-match option
# Git log -- < Path > historical submission of some files or directories. Specify the path after the option

git reset is to roll back to a commit, but it is recommended to use git revert for rollback operation

#The submitted changes will be returned to the staging area
git reset --soft
#No reservation will be made for the changes after the submission, and the git status is a clean workspace
git reset --hard

If git revert abandons a submission, the previous submission will remain in git log, and this revocation will be a new submission. In fact, it creates a submission before rollback

Git cherry pick merges the specified commit to branch

git rebase

Topics: Operation & Maintenance git