recently we moved from TFS to GIT so I am still learning how to use this amazing tool.
At the moment I am working in a very simple structure like the following one:
main -------------------------------------- 01 ----------
\ /
dev ----------------------- 01 ---------- 02 ----------
\ / /
feat/login ------ 01 --- 02 --- 03 --- 04 --- 05 ---
feature/something
and every tot hours they check-in and trigger a build with testsdev
which will contains 1 or more checkins from feature/something
dev
into main
The questions are the following:
feat/login
, if I do git checkout dev
I don't get the latest code from dev
but also my latest local file changed in feat/login
. How can I checkout dev
without carry over the local changes not commited from my previous branch?
rollback
to a previous check-in 01
in dev
and push it so that the latest check-in 02
is not the last one anymore?1) Stash your changes, checkout to another branch, make some changes there and come back to your original branch and apply/pop your stash.
$ git stash
$ git checkout dev
# do something in you dev branch
$ git checkout feat/login
$ git stash apply
You can view your stash list using the command $ git stash list
2) It seems like you want to revert back the changes. I recommend you to not play with git history as a beginner. Anyways, if you do want to try it out here's a good answer how to do it. As Lasse said it's better to create another commit that reverts the effect of the one you want to undo.
Another feature that you may use, is git worktree
(https://git-scm.com/docs/git-worktree) which allows you to have working copies of multiple branches at the same time, so e.g. lets assume you are on master:
git worktree add -b dev ../dev origin/dev
git worktree add -b feat_login ../feat_login origin/feat/login
will give you 2 additional working copies in ../dev and ../feat_login that contain a working copy of the dev and feat_login branch.
I find this feature especially useful in projects were I have to switch between branches very often.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With