powershell Git备忘单(有一些powershell)
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了powershell Git备忘单(有一些powershell)相关的知识,希望对你有一定的参考价值。
## Show single file from another branch
git show [branch]:[pathtofile]
# show file history from across all branches
git log --all -- [pathname]
# oneline
git log --graph --decorate --oneline
# with commit hash
git log --format=%H
git rev-list [start]..[end]
# Find branch with commit
git branch --contains [commit]
git reflog show --all | grep a871742
# git reflog show is actually just an alias for git log -g --abbrev-commit --pretty=oneline, so if you want to fiddle with the output format to make different things available to grep for, that's your starting point!
# get commits with specific text in message
git log --oneline origin/master..HEAD | % { $_ -match "(EC-\d+)" | out-null ; $Matches[0] }| sort -unique
# [Changing a remote's URL - GitHub Help](https://help.github.com/en/articles/changing-a-remotes-url)
git remote set-url origin [new origin]
# get filename from grep command, or something like that
(git grep "prod" ) -split ':' | select -first 10
# pretty format
git log --pretty=format:"%H" HEAD~100..HEAD | % {
$summat = 0
$_.ToCharArray() | % { $summat += [System.Convert]::ToInt32($_, 16) }
$summat
}
# cherry pick
git cherry-pick ( git log dev/EC-2633-SetAsideCreateRefFixes --oneline -9 --reverse --format=%H )
# cherry pick with preferences for theirs not mine
git cherry-pick --strategy=recursive -X theirs <other commit ID>
# search - How to grep Git commit diffs or contents for a certain word? - Stack Overflow <https://stackoverflow.com/questions/1337320/how-to-grep-git-commit-diffs-or-contents-for-a-certain-word>
# Find commit that introduced text
git log -S [whatever] --source --all
# Find commit that added or removed text in code, pickage
git log -Sword
git log -S"word"
git log -Gregexp
git log -G"regexp"
git log --after="2014-7-1" --before="2014-7-4"
# get hashes between two commits
git log topic/Sprint139a origin/topic/Sprint139a..topic/Sprint139a --reverse --format='%H'
# interactively delete branches
git branch | ? { $_ -match 'topic' } | ? { (read-host "Delete $($_.Trim()) [y/N]?" ) -eq 'y' } | % { git branch -D $($_.Trim()) }
# push new branch
git push -u origin [branch]
# git add -p ; git commit
git commit -p
# quick delete branches
git branch | % { $_.Trim() } | ? { $_ -match '^topic' } | % { git branch -D $_ }
# view filenames only and those that still exist
git log --grep=EC-2722 --name-only --format=""
git log --name-only --format="" | sort -unique | ? { test-path "$_" }
[--format] (https://git-scm.com/docs/pretty-formats)
# Get untracked files that could be added
git ls-files --others --exclude-standard
git log --merges
git log --no-merges
# Show files across commit sets
git log --name-only --format='' 092410d000de226966bb044558b593b26c67fc64..dc837352cc05c506ee5703185b670e1f0221a246 | sort -unique | ? { Test-path $_ }
# Get distinct filenames in a commit range that still exist
$commitSet = '092410d000de226966bb044558b593b26c67fc64..dc837352cc05c506ee5703185b670e1f0221a246'
git log --name-only --format='' $commitSet | sort -unique | ? { Test-path $_ }
git remote set-url origin [new url]
# blame with specific line range
git blame -L 1,5 README.md
# Get git clones
gci -Directory -r -Include .git -force | select -ExpandProperty Parent | select -ExpandProperty FullName | ? { -not ( $_ -match "ThirdParty" ) } | % { git -C $_ remote get-url origin }
## Delete branches interactively
git branch | % { $_.Trim() } | ? { $_ -match "topic" } | ? { (read-host "Delete $_ [y/N]") -eq 'y' } | % { git branch -D $_ }
git checkout [branch_name] -- [paths]
##
git remote add origin [remote repo]
git push -u origin master
## Get patches from this commit through HEAD
git format-patch [firsthash^]
## Replace dirs in each patch
gci *.patch | % { ( gc $_ |
% { $_ -replace '[dir1]','[dir1a]' } |
% { $_ -replace '[dir2]','[dir2a]' } |
% { $_ -replace '[dir3]','[dir3a]' } |
% { $_ -replace '[dir4]','[dir4a]' } ) |
sc $_ }
cd [OtherRepo]
## Apply patches to new repo
gci "D:\dev\eCargo\*.patch" | % { git am $_ }
# grep, finding if sprocs are referenced in repository
git ls-files *_old.sql | % { $_ -replace '.*/([^/]*).*\.sql','$1' } | % { git grep -i --name-only $_ }
git ls-files [somepath]/* | % { $_ -replace '.*/([^/]*).*\.sql','$1' } | % { write-host $_ ; git grep -i --name-only $_ | measure-object | select -property Count }
# Filter by filename names, include/exclude
git grep -i 'someterm' -- './*' ':(exclude)*.xml' ':(exclude)*.html'
git grep -i 'insert into' -- [somefolder]/**/*.sql
# With search and replace, extract filename from grep results
git grep -i 'someterm' | % { $_ -split ':' | select -first 1 } | sort -unique | % { (get-content $_ | % { $_ -replace '\bsometerm\b','newtext' }) | set-content $_ }
# Grep in branch and other directories (repos)
git grep -i 'alpha' branch
git grep -i 'alpha' <branch> -- [somepath]
git -C d:\dev\tools grep -i ''
# Match multiple terms
git grep -l --all-match -e frotz -e nitfol
# Show the filename above the matches in that file instead of at the start of each shown line.
git grep --heading "class .*CommandHandler" -- .\[somepath]\**\*.cs | sls "partial class
# grep on multiple terms
git grep -E -i -w 'getThis|getThat'
# view function body
git grep -W 'functionname'
git grep --after-context 5 -h 'somestuff\.morestuff'
# word boundary
git grep -w 'text'
# add headings and break with blank lines
git grep --heading --break -i 'postal_address_1' -- *.sql
#
git -C d:\dev\Tools grep --heading --break -A 3 -i 'selectsinglenode' -- *.ps1
# case insensitive ls-files
git ls-files *.sql | ? { $_ -match 'logistic' }
# show changed files with specific text
git diff --name-only -G"SomeText\."
git status | ? { $_ -match "modified:" } | % { $_ -match "modified:\s+(.*)$" | out-null ; $Matches[1] }
ls | select -ExpandProperty FullName | % { write-host "$_" -ForegroundColor Green ; git -C $_ pull }
以上是关于powershell Git备忘单(有一些powershell)的主要内容,如果未能解决你的问题,请参考以下文章