The git index is a staging area for changes to be committed. Adding files to the index is a common operation in git, and there are several ways to do it.
git add -A #
Automatically add/remove/update a pathspec:
git add -AFrom the manual:
-A, –all, –no-ignore-removal
Update the index not only where the working tree has a file matching
but also where the index already has an entry. This adds, modifies, and removes index entries to match the working tree. If no is given, the current version of Git defaults to “.”; in other words, update all files in the current directory and its subdirectories. This default will change in a future version of Git, hence the form without should not be used.
Squash commits #
Some people get nitpicky about the number of commits in a pull request. If you want to squash the commits here is a way to do it:
# make sure you are on the main branch
git checkout main
# create a new branch
git checkout -b feat/my-feature-branch
# edit files and commit (multiple times)
# create a log file with the commit messages
git log main..feat/my-feature-branch \
--pretty=format:'- %ad %s (%an)' --date=short > log.txt
# or without author
git log main..feat/my-feature-branch \
--pretty=format:'- %ad %s' --date=short > log.txt
# edit the log file to remove the commits you don't want
vi log.txt
# reset the branch to main, but keep the changes in the index
git reset --soft main
# commit the changes in the index
git commit -F log.txt
# push the changes to the remote
git push -f origin feat/my-feature-branch