I have edited some files in the repo and now it looks like the following:
history1 --> history2 --> ... --> master
\
\
my commit 1 --> my commit 2
But actually 'my commit 2' should not be on top of 'my commit 1', that's a mistake... How do I only rebase 'my commit 2' to master in mercury?
history1 --> history2 --> ... --> master
\ \
\ \
my commit 1 my commit 2
I am asking how to do this in Mercurial not git.
Make sure you have the rebase extension enabled in your hgrc file. Then:
$ hg rebase -r <commit ID of my commit 2> -d master
See "hg help rebase" for more details.
From a different post:
You can cherry-pick XX to master.
git checkout master
git cherry-pick <commit ID of XX>
And remove the last commit from the feature branch with git reset.
git checkout Feature-branch
git reset --hard HEAD^
Related
I just tried to rename the branch with following command
git branch -m <oldname> <newname>
my older branch name is feature/AAM-443 and this branch is already merged with parent now when i renamed it with feature/AAMN-443 and push it to remote then the branch in network is showing
*<commit id> feature/AAM-443, feature/AAMN-443
and if i do some commit to feature/AAMN-443 then graph is like
* <new-commit id> feature/AAMN-443
|
|
* <old-commit id> feature/AAM-443
what is happening i am wondering that what the meaning of a branch having two names is it some symbolic reference and why the feature/AAM-443 is still there why not it removed can anyone help
To add to #RomainValeri's answer, a branch can't have two names, so what you did was this:
You had a remote tracking branch:
git branch -a
feature/AAM-443
origin/feature/AAM-443 <-- tracked by feature/AAM-443
You renamed your branch locally:
git branch -m feature/AAM-443 feature/AAMN-443
git branch -a
feature/AAMN-443
origin/feature/AAM-443 <-- still thinks it's tracked by feature/AAM-443
You pushed your renamed branch to origin:
git push -u feature/AAMN-443
git branch -a
feature/AAMN-443
origin/feature/AAMN-443 <-- tracked by feature/AAMN-443
origin/feature/AAM-443 <-- no longer tracked by any local branch!
Then you made a new commit and pushed:
git commit -am "new commit" <-- on branch feature/AAMN-443
Your remote repo updated like this:
o <-- origin/feature/AAMN-443
|
o <-- origin/feature/AAM-443 (branch is no longer tracked! It has been left behind!!)
Like #RomainValeri said, you need to delete origin/feature/AAM-443:
git push --delete origin feature/AAM-443
You just have to remove the remote counterpart that's still there.
(assuming your remote is named origin here)
git push --delete origin feature/AAM-443
# or
git push origin :feature/AAM-443
Context:
assume you have some rather tricky CI/CD workflow which relies on git tags
the feature branches are built and generate some short-lived tags to signify commits which yield the deployable artifacts
when the feature branch gets squash-merged, usually it's deleted, but the tags, unsurprisingly, survive
after, say, several months of development the tag listing predictably becomes hairy
Hence, the question:
how would I, using git command line and, optionally, basic bash tooling
list all the branches which have given tag reachable (the dual to that is git tag -l --merged ${BRANCH_COMMITTISH}, but I need not tags for the given branch but branches for a given tag)
list all the tags which have empty output from point 1 above (obviously this is doable with a for loop (given any terminating implementation for 1), but maybe there's some neat magical git one-liner)?
git log --simplify-by-decoration --tags --not --branches --remotes --pretty=%d
--simplify-by-decoration says only show the bare minimum needed to reveal the ancestry (usually you use this with --graph). --tags --not --branches --remotes says, well, what it says: list the tag history that's not in the branches or remotes history, i.e. tags unreachable from any branch or remote-tracking branch. --pretty=%d says just show the refs.
git branch --contains ${TAG}
https://git-scm.com/docs/git-branch#git-branch---containsltcommitgt.
Just to illustrate all solutions I've seen so far:
~$ git init dangling_tags
Initialized empty Git repository in ~/dangling_tags/.git/
$ cd dangling_tags/
~/dangling_tags$ touch a.txt && git add a.txt && git commit -m a
[master (root-commit) f1b1070] a
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 a.txt
~/dangling_tags$ git tag a
~/dangling_tags$ git checkout -b feature/add_some_tags
Switched to a new branch 'feature/add_some_tags'
~/dangling_tags$ touch b.txt && git add b.txt && git commit -m b
[feature/add_some_tags 1871cde] b
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 b.txt
~/dangling_tags$ git tag b
~/dangling_tags$ touch c.txt && git add c.txt && git commit -m c
[feature/add_some_tags 26f6611] c
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 c.txt
~/dangling_tags$ git tag c
~/dangling_tags$ git checkout master
Switched to branch 'master'
~/dangling_tags$ git merge --squash feature/add_some_tags
Updating f1b1070..26f6611
Fast-forward
Squash commit -- not updating HEAD
b.txt | 0
c.txt | 0
2 files changed, 0 insertions(+), 0 deletions(-)
create mode 100644 b.txt
create mode 100644 c.txt
~/dangling_tags$ git commit
[master 99b33ae] Squashed commit of the following:
2 files changed, 0 insertions(+), 0 deletions(-)
create mode 100644 b.txt
create mode 100644 c.txt
~/dangling_tags$ git branch --contains a
* master
~/dangling_tags$ git branch --contains b
feature/add_some_tags
~/dangling_tags$ git branch -D feature/add_some_tags
Deleted branch feature/add_some_tags (was 26f6611).
~/dangling_tags$ git tag
a
b
c
~/dangling_tags$ git branch --contains a
* master
~/dangling_tags$ git branch --contains b
~/dangling_tags$ for t in $(git tag); do if test "$(git branch --contains $t | wc -l)" == "0" ; then echo $t; fi done
b
c
~/dangling_tags$ git log --simplify-by-decoration --tags --not --branches --remotes --pretty=%d
(tag: c)
(tag: b)
I want to pysh my project to a github repository called luna.git:
I followed the instructions
echo “# luna” >> README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin https://github.com/raouiyounes/luna.git
git push -u origin master
But I get this error
error: src refspec master does not match any.
error: impossible de pousser des références vers ‘https://github.com/raouiyounes/luna.git’
Maybe you just need to commit.
Try this:
git add .
git commit -m "initial commit"
git push origin master
You can do :
git push origin HEAD:branch-name
I want to sync my code to my github repo, so anytime I update my code it should be updated in the repo. Is there any proper and structured way of doing this.
So this is how I am doing it now
1
$ cd my-project
$ git init
$ git remote add origin GITHUB_URL
$ git pull origin master
$ git status
$ git add .
$ git commit -m "Init repo."
$ git push -u origin master
then just repeat following steps
$ git add .
$ git commit -m "Init repo."
$ git push -u origin master
i am getting error sh.exe: notepad: command not found please short out my problem
Thanks
For the commit to GitHub part, you need to add (if you have created an empty yourRepo on GitHub):
git config user.name yourGitHubUsername
git config user.email yourGitHubEmail
git add .
git commit -m "First commit"
git remote add origin https://yourAccount#github.com/yourAccount/yourRepo
git push -u origin master
If that fails because GitHub already created one commit when you initialized your "empty" repo (it can add by default a README.md and a .gitignore), do a:
git pull --rebase origin master
git push -u origin master
If you really have to call notepad from a mingw session, you can use this wrapper:
#!/bin/sh
'C:/Program Files (x86)/Notepad++/notepad++.exe' -multiInst -notabbar \
-nosession -noPlugin "$(cygpath -w "$*")"
But remember you can use msysgit from a DOS session as well.
Seps:
1.git init
2. git status
3. git add .
4. git commit -a
5. git status