git cherry-pick <COMMIT_HASH_FROM_ANY_BRANCH>
git checkout <SOURCE_BRANCH> -- <PATH_TO_FILE>
This can be used, for example, to recover deleted files from another branch.
git checkout stash@{<STASH_NUMBER>} -- <FILE_NAME>
git add -p <PATH_TO_FILE>
After adding, commit the changes as usual.
# do changes in the file if applies
git [add|rm|reset] <PATH_TO_FILE>
git commit --ammend
Same mechanism as before:
git commit --amend
And change the message in the top of the editor.
If exist in remote, after change it, push it with --force
to overwrite the last commit message in remote.
More info in GitHub.
Example: having 3 commits, we want to modify all the previous commit messages (valid for any of them individually as well):
git rebase -i HEAD~3 # or use the last commit reference
the editor will be prompted and should remain as follow:
pick 2f05aba ... # will be preserved
reword daed25c ... # it's message will be modified; or just `r` instead of `reword`
reword e2b2a84 ... # it's message will be modified
From this on, rebase will prompt one editor per reword commit in order to modify it's message, just modify, save and continue.
Once all the changes are made, force push is needed to overwrite remote commit log:
git push --force
Example: having 3 commits, we want to skip the 2th:
git rebase -i HEAD~3 # or use the last commit reference
the editor will be prompted and should remain as follow:
pick 2f05aba ... # will be preserved
drop daed25c ... # will be dropped; or just `d` instead of `drop`
pick e2b2a84 ... # will be preserved
Once all the changes are made, force push is needed to overwrite remote commit log:
git push --force
git stash clear
This change affect to the global git configuration, every git project that does not define core.filemode
directive will be affected:
git config --global core.filemode false
To apply to a specific project, under the git project root folder:
git config core.filemode false
```## Reset remote git commit
```sh
git reset HEAD~<NUMBER_COMMITS_BACK>
or
git reset --hard <COMMIT_HASH>
After this, push it to remote overwriting the last message:
git push origin HEAD --force
This change affect to the global git configuration, every git project that does not define core.filemode
directive will be affected:
git config --global user.name "User name"
git config --global user.email "my@email.tld"
To apply to a specific project, under the git project root folder:
git config user.name "User name"
git config user.email "my@email.tld"
git commit --amend --author="Author Name <email@address.com>"
https://stackoverflow.com/a/3042512/4411354
Add entries into .git/info/exclude
.
In case of having unstaged changes, you need to explicitly ignore them: git update-index --assume-unchanged <PATH_TO_FILE>
.
If you are in the branch to rename:
git branch -m <NEW_BRANCH_NAME>
or if you are in another branch:
git branch -m <OLD_BRANCH_NAME> <NEW_BRANCH_NAME>
To remove the old branch from remote and push the new one:
git push origin :<OLD_BRANCH_NAME> <NEW_BRANCH_NAME>
Reset the upstream branch:
git push origin -u <NEW_BRANCH_NAME>