There is a change in my gerrit server that I pull and checkout in my local repo like this:
git fetch <repoURL> refs/changes/<xx/yyyyyy/z> && git checkout FETCH_HEAD
After that my local repo switches to some detached state commit, in which I want to work the usual way I do with git e.g.:
add another commit with the (still lacking in the downloaded gerrit change) change
unite those two into one preserving the original commit message (with gerrit Change ID):
git rebase -i HEAD~2
Now can I just push to gerrit (in order to create a new (next) gerrit patchset) with:
3. git push <repoURL> HEAD:refs/for/branch
or do I have to push with force:
3. git push -f <repoURL> HEAD:refs/for/branch
First of all, what is the state of the change you have fetched? Is it "open" (not merged) or "closed" (merged)?
If it's merged, you don't need to download the change using the fetch/checkout commands, you should just fetch your repository and get the change in the branch (since it is already integrated).
If it's not merged, what do you want to do? Do you want to fix the change or do you want to make another change based on this change?
I suppose by your text that you want to fix the change (since you intend to join the changes), then the correct way to do is the following:
1- Download the change:
git fetch <repoURL> refs/changes/<xx/yyyyyy/z> && git checkout FETCH_HEAD
2- Make your change
3- Amend the commit (keeping the same Change-Id)
git commit --amend
4- Push the amended commit
git push <repoURL> HEAD:refs/for/branch
Related
I have looked at many past posts without a specific response. I used git reset --hard to get me to a point in time when my code was not all jacked up. Yes I should have used a branch but I didn't. Now I have a message of HEAD is now at 0600b73 fixed error. What I would like to know is how to commit those changes, so I can push them back to Git, so they are the current head? I am not even sure if VS Code even recorded the changes. Git can be confusing so any help would be appreciated.
You haven't actually proven you have changes, HEAD is now at 0600b73 fixed error., that does not mean you have changes. That basically means that you moved the HEAD of git to a commit, generally you want it on a branch.
git status will tell you if you have things that need to be committed.
I am not even sure if VS Code even recorded the changes
VScode has some cool features around git but it doesn't actually record changes, unless you are referring to saving files. If you save the file, well it saves.
What you probably want to do is (I am assuming you actually do have changes):
confirm you have changes git status
move to a branch git checkout -b my-fix
add those changes git add . (adds all changes/also make sure you are at the root of the repo) or git add -p will let you look closely at changes and give you an interface to decide if you want to stage the change or not.
commit the changes git commit -m "Your message" or you can do a longer message with git commit -p
At this point you can merge this branch in to master, push the branch. It's up to you.
push your changes, git push origin my-fix, make a pull request and merge to master. You will then want to change to master and pull master
merge git checkout master , git merge my-fix
rebase git checkout master , git rebase my-fix
Here is some git learning material:
https://learngitbranching.js.org/
https://www.codecademy.com/learn/learn-git
https://try.github.io/
https://www.atlassian.com/git
I'd like to delete the GitHub blame history that GitHub shows (tracking all changes made)
I am aware of how to how to roll back changes, but I am not trying to roll back any changes I have made, I am simply trying to delete this history of the changes.
Obviously, I do own the repository that I will be operating on (and am the sole owner)
If this is for all files of your GitHub repository, the simplest way would be to:
initialize a new local repository
add files from the original repo
add as remote the original repo GitHub URL
force push
That is:
git clone https://github.com/me/myrepo
git init myrepo2
cd repo2
git --work-tree=../myrepo add .
git checkout # -- .
git commit -m "Import myrepo"
git remote add origin https://github.com/me/myrepo
git push --force -u origin master
I'm using Github to store my projects, and would like to know if there is a way for me to get my repository to automatically update in real time.
To clarify what I mean, I'm currently using the good old "git clone" "git add" "git commit" "git push" technique, but it's becoming rather tedious.
What mechanism can I put in place to achieve that?
On the push side, you can use a local .git/hooks/post-commit that includes:
#!/bin/sh
git push origin master
(assuming here you are pushing from master: you have other options at "How to automatically push after committing in git?")
If you want a local repo always up-to-date with a remote GitHub repo, you can setup a webhook which will listen for push events and automatically pull for you.
See for instance this webhook (or this one):
<?php
// Use in the "Post-Receive URLs" section of your GitHub repo.
if ($_SERVER['HTTP_X_GITHUB_EVENT'] == 'push') {
shell_exec( 'cd /srv/www/git-repo/ && git reset --hard HEAD && git pull' );
}
?>hi
The OP NodziGames decided in the comments to go for a more "on demand" approach:
create a Makefile where I can clone, add new files, commit and push via a single command.
I had a branch on a GitHub project that I merged into master. I then clicked the 'delete branch' button on GitHub, and thought I was all set.
Turns out I wasn't, and I want to restore/reactivate the branch. I did not delete the branch on my local respository, nor did I run any git fetch/pull afterward. Just clicked the delete button on GitHub.
Wanted to sound out what a good next step should be. Thinking of doing git push from my local box but wasn't sure what the repercussions might be, would the remote repo on GitHub squawk about a dead branch being brought back, etc.
If you didn't remove your branch from your local machine, and you got rights to push to GitHub, you can restore it on Github by pushing it again
git checkout localBranchName
git push origin localBranchName
It doesn't matter if you make a fetch from Github, git wont remove your local branch until you explicitly tell it to do so with
git branch -D localBranchName
In fact, even if you had removed your local branch, if you merged it previously with master, you can restore it locally. You have to go to the last commit, prior to the merge and branch from there. Something like this for example:
git checkout master
git checkout -b localBranchName
git reset --hard HEAD~1 ( 1 is the number of commits you want to undo )
The second command will create a new branch pointing to your last commit on master
The third command will the last commit undoing (only on that branch ) the merge with master.
Another thing you can do is use "git reflog". That command is very usefull since it will show each time you moved between branches and/or commits.
Go to your list of commits. Find the commit with the merge and click on the pull request number (the number prefixed with #). This will direct you to a page with info about the merge and a button with the label 'Restore branch'. Click that and it is restored.
It looks like there is a "Restore branch" button now that shows up in place of the "Delete branch"
I've had problems using git pull origin SomeBranch in that when there are conflicts, sometimes I cannot open a file in Xcode to resolve the conflict.
From my reading, although I could be wrong, I thought git fetch grabs the code but does not merge it yet like git pull does. How does this work with Xcode?
For example, on one machine on Branch1, I put in some changes.
Then on machine 2, on Branch2, I want to fetch Branch1 changes.
So I did this
git fetch origin Branch2
My output from the command line was:
*branch Branch2 -> FETCH_HEAD
What does this mean? When I go to the source file of the file that I changed, I do not see any changes made.
I thought what would happen is in Xcode, it would then show the changes of that file in that source file and that file would then be Modified. And only when I commit would it be added to the staging area so I could merge it with everything else. But maybe I am understanding it incorrectly. Thoughts? Thanks.
I thought git fetch grabs the code but does not merge it yet like git pull does.
Yes, that is correct. git merge is what updates your working directory, which is why...
When I go to the source file of the file that I changed, I do not see any changes made.
git fetch retrieves the objects that represent the changes, but does not update your working directory. That's what git merge does. Remember that git pull is basically a git fetch followed by a git merge.
fetch just updates your remote tracking branch.
This allows you to inspect what was pulled down from the server before integrating those changes with what you have locally.
You now either merge or rebase those changes to your local branch (if it exists). If it doesn't, you can simply
git checkout branch2
if it does,
git merge origin/branch2
or
git rebase origin/branch2
to skip this 2 step process, just
git pull origin branch2
which will by default merge. You can override with
git pull --rebase origin branch2
you can change your config so that pull will always rebase instead of merge.
For a Git repository, you need to save changes you’ve made and commit them to your local repository before updating changes from the shared repository.
https://developer.apple.com/library/ios/recipes/xcode_help-source_control_management/UpdatingorPullingChanges/UpdatingorPullingChanges.html