Git notes: Difference between revisions
Jump to navigation
Jump to search
mNo edit summary |
|||
Line 37: | Line 37: | ||
cd my_repo | cd my_repo | ||
git reset --hard [ENTER HERE THE COMMIT HASH YOU WANT] | git reset --hard [ENTER HERE THE COMMIT HASH YOU WANT] | ||
</pre> | |||
== Change submodule URL == | |||
This is very much a hammer way of doing this. I have seen elegant ways online, but they seem inconsistent when something goes wrong. This way is reproducible as far as I am concerned. | |||
<pre> | |||
edit .gitmodule | |||
change values | |||
rm -rf directory/ | |||
git submodule update --init --recursive --remote | |||
git add -A | |||
git commit -m 'save new submodule changes' | |||
git push | |||
</pre> | </pre> | ||
Revision as of 12:31, 8 February 2024
General git commands that are useful
Change git remote:
With or without ssh keys added to your user account..
git remote set-url origin git@gitlab01.iwillfearnoevil.com:monitoring/nmsui.git or: git remote set-url origin https://gitlab01.iwillfearnoevil.com/monitoring/nmsui.git
Sort git branches by last commit
git for-each-ref --sort=committerdate refs/heads/ --format='%(HEAD) %(color:yellow)%(refname:short)%(color:reset) - %(color:red)%(objectname:short)%(color:reset) - %(contents:subject) - %(authorname) (%(color:green)%(committerdate:relative)%(color:reset))'
Show git commit hashes for each branch sorted by date
git for-each-ref --sort=-committerdate refs/heads/
Do a git diff between two branches
git diff <branch>..origin/<branch2>
Update Submodules
pull-latest-changes-for-all-git-submodules
git submodule update --recursive --init git submodule update --recursive --remote
Checkout specific commit hash
This can be useful when the hash is not in the expected branch, or when you are in a detached head state
git clone [remote_address_here] my_repo cd my_repo git reset --hard [ENTER HERE THE COMMIT HASH YOU WANT]
Change submodule URL
This is very much a hammer way of doing this. I have seen elegant ways online, but they seem inconsistent when something goes wrong. This way is reproducible as far as I am concerned.
edit .gitmodule change values rm -rf directory/ git submodule update --init --recursive --remote git add -A git commit -m 'save new submodule changes' git push
Change remote URL
git remote set-url origin new.git.url/here