Win a copy of Secure Financial Transactions with Ansible, Terraform, and OpenSCAP this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Rob Spoor
  • Henry Wong
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh
  • Jj Roberts

How to remove changes done to a certain member from my queue in GIT.

 
Rancher
Posts: 1090
14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Is there an easy way to remove a certain member from my queue in GIT?

Following are the specific details.

We have a main branch, say Something_2014_R2. Every developer in our team clones code from this branch and creates his/her own queue. Let us say that my queue is 'Something_2014_R2_Chan'.

So when we work on things, we push the changes to our own queue. Twice in a week, somebody merges reviewed code changes from all developers' queues into the main branch and then a build is created which is then given to QAs for testing.

Now I have about 4-5 commits ( luckily non conflicting -- no other developer has changes done to these members in the current release) done in my queue. Because of requirements changing too fast, I have some members that have gone into my commits but those members actually require no code change as per the latest requirement changes. The problem is the changes to some of these members were done before the two most recent commits to my queue. So it's not like I can revert changes while pushing my code changes to my queue. Is there a way I could just remove these members from the changes that should be merged with the main branch?

I know that I can take a backup of my code changes, point the head to a previous commit, and to a previous commit and so on and revert all those code changes and then redo the code changes that are required. But is there an easier way?

Thanks for the help.
Chan.
 
Chan Ag
Rancher
Posts: 1090
14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For now, I have gotten around the problem by taking a code backup, resetting the three commits, and making the required code changes only from the backed up files, and checking in the new changes only.

I think there must be an easier way to remove some files from the staging area without affecting the tracked files. I will try to read the GIT tutorial in this weekend and if I get the answer before anyone else has had an opportunity to answer it, I shall post my answer here.

Thanks for spending time to read my question. I really appreciate it.

I know I should have read the tutorial myself before posting the question. I tried to do that, but the GIT tutorial is quite 'not too easy to understand' and I didn't want to do a trial and error thing with code changes that I wasn't going to take a backup of. I realized I need to spend some good time with the GIT tutorial to understand the commands right from the beginning. I can do that only on the weekend. Hence this response.

Sorry in advance for posting the question without first completely reading the tutorial ( I really tried for some time... but I gave up on it because of lack of time just right now ) and then saying I got around the problem with the help of a workaround.
 
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For getting started with Git and understanding the very basics of it, I highly recommend the freely available Pro Git book here http://git-scm.com/book. When I started with Git, I found this to be the best resource to understand the basics. Once I got a hang of those basics, I was comfortable enough to try out my own way of doing things in Git and the commands were no longer intimidating.
 
Jaikiran Pai
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
To answer your original question, on how to get rid of the local commit in your local repo, I can think of at least 2 ways of doing that.

1) The usual git revert command, where you specify the commit SHA and have the commit reverted. This command additionally creates a new commit which reverts the commit that you selected. So if your commit log was something like this, before the revert:

commit D
commit C
commit B
commit A

and you reverted commit B, then after the revert, the commit log will be:

commit E <-- This is the new commit which reverts the changes in commit B
commit D
commit C
commit B
commit A

You can then just push these changes to your remote repo and then have it merged to the main repo.

Sometimes, developers might not want to see the additional commit E and not even commit B (for example, if the commit was just some local testing they were doing). In such cases, there's one other way of handling the revert:

2) First do a git log to check the commits and select the commit you want to revert to. Let's again consider the same commit history as above and let's assume you are currently on a local branch named "foo":

commit D
commit C
commit B
commit A

Again, let's assume you want to get rid of commit B.

The first step is to "go to" A and have a new local branch created where "A" is the latest/topmost commit in that branch. So here's what you do:



the -b option instructs git to create a new branch named "bar" and that whole command tells git to create a branch named "bar" whose latest/topmost commit is A. git also now automatically switches you to that new branch. You can check what branch you are on, by doing:


It will show you all the branches in your local repo and there will be * beside the current branch that you are on. Since you did a new branch creation and checkout with the last command, you will now be on "bar" branch.

Now issue a git log command and you'll notice that the latest commit is commit A:

commit A

Now moving on to the next step, you now want to "pick" commit C and commit D and apply it on top of the current commit A. There's a command known as cherry-pick which helps you do that. You just pass it the commit SHA to that command and it will "pick" and apply that commit to the current branch. So you'll first do:



and then



Now when you do a git log, you'll see:

commit D
commit C
commit A

and that's the commit history you wanted.

You can delete the "foo" local branch and rename this current "bar" branch to foo and push it to your remote repo or you can directly push this bar branch to your remote repo and in either case have it merged to the master repo.
 
Chan Ag
Rancher
Posts: 1090
14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the link and that detailed explanation, Jaikiran.

Sorry I couldn't respond earlier cause I was in another city with limited access to internet. I am going to try these options today. I really appreciate your being so helpful.


 
And then the flying monkeys attacked. My only defense was this tiny ad:
SKIP - a book about connecting industrious people with elderly land owners
https://coderanch.com/t/skip-book
reply
    Bookmark Topic Watch Topic
  • New Topic