git commit --amend
The command amend
changes the latest commit by replacing with the new one. Suppose you have changes in working directory, by running git commit --amend
the new changes will be committed as replacement of the old latest commit. If there is no new changes, this command will let you change commit comment of the latest commit and save as new commit replacing old latest commit.
# undo commit
git reset --soft HEAD~1
# undo add
git reset HEAD
The above commands let you clear latest commit and add. The changes will remain as unstaged files in working directory.
# delete on local first
git branch -d <branch>
# push to remote using :
git push origin :<branch>
# locally merge with adding new comment to the commit
# where x is the number of HEAD to be merged
git reset --soft HEAD~x && git commit -m "<comment>"
# remotely merge can be confusing
# first way is just force push what local is merged to remote
git reset --soft HEAD~x && git commit -m "<comment>"
git push origin +<branch>
# second way
git rebase -i origin/master~x master
git push origin +<branch>
src: locally, remotely (second way)
git rm --cached <filename>
git remote add origin <repo>
git push -u origin master # pushes up the repo and its refs for the first time
Changing URL between SSH and HTML can use git remote set-url
too.
git remote set-url <remote name> <repo>
# remote name can be origin or upstream in common.
git remote -v # list existing remote names
# set
git config --global http.proxy http://<username>:<password>@<proxy server>:<proxy port>
git config --global https.proxy https://<username>:<password>@<proxy server>:<proxy port>
#unset
git config --global --unset http.proxy
git config --global --unset https.proxy