-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Git Commands #7
Comments
git filter-branchRemove files in commits git filter-branch --index-filter 'git rm --cached --ignore-unmatch public/*' HEAD Remove empty commits git filter-branch --commit-filter 'git_commit_non_empty_tree "$@"' -f HEAD Update name and email in commits git filter-branch --env-filter '
WRONG_EMAIL="nntrn@wrong.com"
NEW_NAME="nntrn"
NEW_EMAIL="17685332+nntrn@users.noreply.github.com"
if [ "$GIT_COMMITTER_EMAIL" = "$WRONG_EMAIL" ]
then
export GIT_COMMITTER_NAME="$NEW_NAME"
export GIT_COMMITTER_EMAIL="$NEW_EMAIL"
fi
if [ "$GIT_AUTHOR_EMAIL" = "$WRONG_EMAIL" ]
then
export GIT_AUTHOR_NAME="$NEW_NAME"
export GIT_AUTHOR_EMAIL="$NEW_EMAIL"
fi
' -f HEAD Remove commits by author git filter-branch --commit-filter '
if [ "$GIT_AUTHOR_NAME" != "nntrn" ];
then
skip_commit "$@"
else
git commit-tree "$@"
fi' -f HEAD |
git filterHide secrets in commits# ~/.gitconfig or .git/config
[filter "cleanPass"]
clean = sed -e 's/secretpassword/hiddenpassword/g'
smudge = sed -e 's/hiddenpassword/secretpassword/g' # .gitattributes or .git/info/attributes
.env text eol=lf filter=cleanPass $ echo "PASSWORD=secretpassword" >.env
$ git add .env
$ git commit -m "Add .env"
$ git show HEAD:.env
PASSWORD=hiddenpassword
$ cat .env
PASSWORD=secretpassword Source: https://developers.redhat.com/articles/2022/02/02/protect-secrets-git-cleansmudge-filter |
Preserve changesThis method creates a new branch from your current one to preserve your changes. The commits on the new branch are undone, and then only the files you want to preserve are recommitted. # This preserves your old files.
git checkout -b new_branch_name
# See the list of your commits. # Find the hash of the last commit before your changes.
git log
# Where abcdef is the hash found in the step above.
git reset --soft abcdef
# Commit the found files into the new_branch_name.
git commit <files_to_preserve> -m "preserved files" |
Global changesTo make global changes across the source tree, it‘s often easiest to use sed -i -E 's/\s+$//' $(git ls-files '*.cpp' '*.h') You may also find
Remember that you can restrict sed actions to matching (or non-matching) lines. For example, to skip lines with a line comment, use the following: '\,//, ! s/foo/bar/g' |
Source: Answer to What's the difference between git switch and git checkout <branch> |
label git diffMOD_PATTERN='^.+(\[-|\{\+).*$' \
ADD_PATTERN='^\{\+.*\+\}$' \
REM_PATTERN='^\[-.*-\]$' \
git diff --word-diff --unified=0 | sed -nr \
-e "s/$MOD_PATTERN/modified/p" \
-e "s/$ADD_PATTERN/added/p" \
-e "s/$REM_PATTERN/removed/p" \
| sort | uniq -c |
ls-tree
List files in another branch
git config
Speed up Git in Windows
# get latest commit id git rev-parse upstream/master
The text was updated successfully, but these errors were encountered: