Hızlı yanıt: kod örneği
Another way to squash all your commits is to reset the index to :Note: Git's default branch name is still with Git version 2.41 (Q3 2023), as seen in man page.Git version 2.28 (Q3 2020) introduced configurable default branch names, which means your remote repository may optionally use another default branch name such as . In order to provide the most universally applicable examples, as well as avoid confusion, this answer shall assume Git's default configuration.If you need the following commands to work for any default branch, replace with .
And define .Back to the solution: (to squash all your commit) reset the index to :This isn't perfect as it implies you know from which branch "" is coming from.
Note: finding that origin branch isn't easy/possible with Git (the visual way is often the easiest, as seen here).Note: has been introduced with Git 2.22 (Q2 2019).Or, as noted by Hiroki Osame in the comments: (or )
See " vs. "Karlotcha Hoa adds in the comments:For the reset, you can do[That] automatically uses the branch you are currently on.
And if you use that, you can also use an alias, as the command doesn't rely on the branch name.
master
master
git init
main
master
${defaultBranch}
defaultBranch=$(git config --get init.defaultBranch || echo main)
master
git checkout yourBranchgit reset $(git merge-base master $(git branch --show-current))git add -Agit commit -m "one commit on yourBranch"
yourBranch
git branch --show-current
git switch yourBranchgit reset --soft $(git merge-base master HEAD)git commit -m "one commit on yourBranch"
- no need for since HEAD is already a reference to that branch.
git branch --show-current
- no need for , since
git add -A
only moves HEAD, and leaves the index untouched (in other words, the files are already "added").git reset --soft
git push --force
git push --force-with-lease
git push --force-with-lease
--force
git reset $(git merge-base master $(git rev-parse --abbrev-ref HEAD))