Git(读音为/gɪt/)是一个开源的分布式版本控制系统,可以有效、高速地处理从很小到非常大的项目版本管理。 也是Linus Torvalds为了帮助管理Linux内核开发而开发的一个开放源码的版本控制软件。分布式相比于集中式的最大区别在于开发者可以提交到本地,每个开发者通过克隆(git clone),在本地机器上拷贝一个完整的Git仓库。
# 克隆仓库
git clone git@github:GerritCodeReview/gerrit.git# 查看分支
git branch
git branch -a
git branch -vva# 切换分支
git checkout main
git checkout -b main origin/main# 查看修改状态
git status .# 查看修改内容
git diff .# 提交仓库方法
git add .
git commit -m "commit msg"
git push origin main# 查看提交记录
git log
git log --oneline
git log --oneline --grep="" --after="" --before="" --author="" .
git reflog# 查看修改详情
git show .
git show commit_id
git show commit_id --stat# 初始化仓库
git init# 拉取更新
git pull
git pull --rebase# 清理修改
git clean
git clean -xdf
git clean -df# 将没有放入缓存区(git add)之前的文件恢复到工作区状态
git checkout .# 回退版本
git reset --hard HEAD^
git reset --hard HEAD~5
git reset --hard commit_id
git reset --hard FETCH_HEAD# 将commit的最后一笔回退到暂存区
# commit-id 为要回退的这笔提交的前一个commitId
git reset commit-id # 暂存
git stash
# 暂存取出
git stash pop
tag是git版本库的一个标记,指向某个commit的指针。
# 创建本地tag(基于本地当前分支的最后的一个commit 创建的 tag)
git tag <tagName>
# 推送到远程仓库
git push origin <tagName>
# 若存在很多未推送的本地标签,你想一次全部推送的话:
git push origin --tags
# 只想以某一个特定的提交为tag ,只要你知道commit 的id。
git tag -a <tagName> <commitId>
# 可以指定tag标签信息。
git tag -a <tagname> -m " # 查看本地某个 tag 的详细信息:
git show <tagName>
# 查看本地所有 tag:
git tag 或者 git tag -l
# 查看远程所有 tag:
git ls-remote --tags origin# 本地 tag 的删除:
git tag -d <tagName>
# 远程 tag 的删除:
git push origin :refs/tags/<tagName># 检出标签
git checkout -b <branchName> <tagName>
1.选择需要pick的节点,前不含后含,pick命令:
git 11a5383ae2.后续根据提示解决冲突,add 修改后,使用命令:
git cherry-pick --continue ,直到没有冲突提示即可3.提交:git push origin HEAD:refs/for/freeme-11.0.0_master4.如提交报错To ssh://10.20.40.21:29418/Freeme/platforms/common/apps/FreemeSettings
! [remote rejected] HEAD -> refs/for/freeme-11.0.0_master (change :8081/#/c/Freeme/platforms/common/apps/FreemeSettings/+/99765 closed)
error: failed to push some refs to 'ssh://fangjian@10.20.40.21:29418/Freeme/platforms/common/apps/FreemeSettings'1)根据提示链接中的commit message找到此提交,使用命令git rebase -i 删除提交节点即可2)如链接无法在gerrit中打开,使用二分法提交,直到找到这笔提交,可以使用该命令进行部分提交:git push origin da75bc971:refs/for/freeme-11.0.0_master
prod分支 -- 产品分支
master分支 -- 平时修改分支同步代码:
先切换到要同步到的分支上(prod分支 -- product分支),remotes/origin后面跟平时修改的分支
git merge --no-ff --no-commit remotes/origin/freeme-11.0.0_master-sprd
# merge 的时候注意冲突修复
# commit的是从哪里merge的
git commit -m "ROUTINE: merge branch 'freeme-11.0.0_master-sprd'"
git push origin HEAD:refs/for/xxxx
git合并时冲突 解决方法:
<<<<<<< HEAD
本地代码
=======
拉下来的代码
>>>>>>>
根据需要删除代码就行了,完事把<<<<<<< ======= >>>>>>都删掉冲突就解决了
git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"
AOSP输出全部修改点
repo forall -pc 'git lg --after="2022-11-8" --before="2022-11-24"' >
1.Gerrit - 某个提交点 - Download - Cherry Pick - copy pick命令
2.在本地仓库运行此命令
3.正常运行即成功,即可提交到远程仓库git push origin HEAD:refs/for/main如报错
1.解决冲突
2.git add <modify-file-path>
3.git cherry-pick --continue
4.git push origin HEAD:refs/for/main
git rebase的两种用法(最全)_小垚尧的博客-CSDN博客_git rebase
# 变基操作
git rebase -i# 合并多个commit,从上到下,commit 越新
在 commit 前修改 pick 为 s 后保存即可# 修改commit记录
注释多余提交信息后保存即可pick p 保留该commit
reword r 保留该commit,但需要修改该commit的注释
edit e 保留该commit, 但我要停下来修改该提交(不仅仅修改注释)
squash s 将该commit合并到前一个commit
fixup f 将该commit合并到前一个commit,但不要保留该提交的注释信息
exec x 执行shell命令
drop d 丢弃该commit
$ git help -a
See 'git help <command>' to read about a specific subcommandMain Porcelain Commandsadd Add file contents to the indexam Apply a series of patches from a mailboxarchive Create an archive of files from a named treebisect Use binary search to find the commit that introduced a bugbranch List, create, or delete branchesbundle Move objects and refs by archivecheckout Switch branches or restore working tree filescherry-pick Apply the changes introduced by some existing commitscitool Graphical alternative to git-commitclean Remove untracked files from the working treeclone Clone a repository into a new directorycommit Record changes to the repositorydescribe Give an object a human readable name based on an available refdiff Show changes between commits, commit and working tree, etcfetch Download objects and refs from another repositoryformat-patch Prepare patches for e-mail submissiongc Cleanup unnecessary files and optimize the local repositorygitk The Git repository browsergrep Print lines matching a patterngui A portable graphical interface to Gitinit Create an empty Git repository or reinitialize an existing onelog Show commit logsmerge Join two or more development histories togethermv Move or rename a file, a directory, or a symlinknotes Add or inspect object notespull Fetch from and integrate with another repository or a local branchpush Update remote refs along with associated objectsrange-diff Compare two commit ranges (e.g. two versions of a branch)rebase Reapply commits on top of another base tipreset Reset current HEAD to the specified staterestore Restore working tree filesrevert Revert some existing commitsrm Remove files from the working tree and from the indexshortlog Summarize 'git log' outputshow Show various types of objectssparse-checkout Initialize and modify the sparse-checkoutstash Stash the changes in a dirty working directory awaystatus Show the working tree statussubmodule Initialize, update or inspect submodulesswitch Switch branchestag Create, list, delete or verify a tag object signed with GPGworktree Manage multiple working treesAncillary Commands / Manipulatorsconfig Get and set repository or global optionsfast-export Git data exporterfast-import Backend for fast Git data importersfilter-branch Rewrite branchesmergetool Run merge conflict resolution tools to resolve merge conflictspack-refs Pack heads and tags for efficient repository accessprune Prune all unreachable objects from the object databasereflog Manage reflog informationremote Manage set of tracked repositoriesrepack Pack unpacked objects in a repositoryreplace Create, list, delete refs to replace objectsAncillary Commands / Interrogatorsannotate Annotate file lines with commit informationblame Show what revision and author last modified each line of a filebugreport Collect information for user to file a bug reportcount-objects Count unpacked number of objects and their disk consumptiondifftool Show changes using common diff toolsfsck Verifies the connectivity and validity of the objects in the databasegitweb Git web interface (web frontend to Git repositories)help Display help information about Gitinstaweb Instantly browse your working repository in gitwebmerge-tree Show three-way merge without touching indexrerere Reuse recorded resolution of conflicted mergesshow-branch Show branches and their commitsverify-commit Check the GPG signature of commitsverify-tag Check the GPG signature of tagswhatchanged Show logs with difference each commit introducesInteracting with Othersarchimport Import a GNU Arch repository into Gitcvsexportcommit Export a single commit to a CVS checkoutcvsimport Salvage your data out of another SCM people love to hatecvsserver A CVS server emulator for Gitimap-send Send a collection of patches from stdin to an IMAP folderp4 Import from and submit to Perforce repositoriesquiltimport Applies a quilt patchset onto the current branchrequest-pull Generates a summary of pending changessend-email Send a collection of patches as emailssvn Bidirectional operation between a Subversion repository and GitLow-level Commands / Manipulatorsapply Apply a patch to files and/or to the indexcheckout-index Copy files from the index to the working treecommit-graph Write and verify Git commit-graph filescommit-tree Create a new commit objecthash-object Compute object ID and optionally creates a blob from a fileindex-pack Build pack index file for an existing packed archivemerge-file Run a three-way file mergemerge-index Run a merge for files needing mergingmktag Creates a tag objectmktree Build a tree-object from ls-tree formatted textmulti-pack-index Write and verify multi-pack-indexespack-objects Create a packed archive of objectsprune-packed Remove extra objects that are already in pack filesread-tree Reads tree information into the indexsymbolic-ref Read, modify and delete symbolic refsunpack-objects Unpack objects from a packed archiveupdate-index Register file contents in the working tree to the indexupdate-ref Update the object name stored in a ref safelywrite-tree Create a tree object from the current indexLow-level Commands / Interrogatorscat-file Provide content or type and size information for repository objectscherry Find commits yet to be applied to upstreamdiff-files Compares files in the working tree and the indexdiff-index Compare a tree to the working tree or indexdiff-tree Compares the content and mode of blobs found via two tree objectsfor-each-ref Output information on each refget-tar-commit-id Extract commit ID from an archive created using git-archivels-files Show information about files in the index and the working treels-remote List references in a remote repositoryls-tree List the contents of a tree objectmerge-base Find as good common ancestors as possible for a mergename-rev Find symbolic names for given revspack-redundant Find redundant pack filesrev-list Lists commit objects in reverse chronological orderrev-parse Pick out and massage parametersshow-index Show packed archive indexshow-ref List references in a local repositoryunpack-file Creates a temporary file with a blob's contentsvar Show a Git logical variableverify-pack Validate packed Git archive filesLow-level Commands / Syncing Repositoriesdaemon A really simple server for Git repositoriesfetch-pack Receive missing objects from another repositoryhttp-backend Server side implementation of Git over HTTPsend-pack Push objects over Git protocol to another repositoryupdate-server-info Update auxiliary info file to help dumb serversLow-level Commands / Internal Helperscheck-attr Display gitattributes informationcheck-ignore Debug gitignore / exclude filescheck-mailmap Show canonical names and email addresses of contactscheck-ref-format Ensures that a reference name is well formedcolumn Display data in columnscredential Retrieve and store user credentialscredential-store Helper to store credentials on diskfmt-merge-msg Produce a merge commit messageinterpret-trailers Add or parse structured information in commit messagesmailinfo Extracts patch and authorship from a single e-mail messagemailsplit Simple UNIX mbox splitter programmerge-one-file The standard helper program to use with git-merge-indexpatch-id Compute unique ID for a patchsh-i18n Git's i18n setup code for shell scriptssh-setup Common Git shell script setup codestripspace Remove unnecessary whitespaceExternal commandsaskyesnocredential-helper-selectorflowlfs
本文发布于:2024-02-04 05:17:58,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/170699962152439.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |